Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>Untitled Document</title>
- <link rel="stylesheet" href="home_styler.css">
- <link rel="stylesheet" href="table_styler_common.css">
- </head>
- <body>
- <div class="header">
- <h1>Welcome!!!!</h1>
- </div>
- <div id="main">
- <label >Destination </label>
- <select name="Des" id="des" class="form-control" onChange="admSelectCheck()">
- <?php
- $host="localhost";
- $user="root";
- $password="";
- $db="transport_system";
- $link = mysqli_connect($host,$user,$password,$db);
- $stop_name=array();
- $bus_name_sql="SELECT Stop_name FROM stops";
- $result = mysqli_query($link,$bus_name_sql) or die(mysqli_error($link));
- $noOfData = mysqli_num_rows($result);
- while($row = mysqli_fetch_row($result)){
- $stop_name[]=$row[0];
- }
- ?>
- <?php for($i=0;$i<$noOfData;$i++){ ?>
- <option selected><?php echo $stop_name[$i]?></option>
- <?php } ?>
- </select>
- </div>
- <script>
- function admSelectCheck(){
- var e = document.getElementById("des");
- var selected_stop = e.options[e.selectedIndex].text;
- //document.getElementById("bus_names").style.display = "block";
- <?php
- //$sel_dest = "<script>document.write(selected_stop)</script>";
- //echo "$sel_dest";
- ?>
- }
- </script>
- <div id="bus_names">
- <script>
- var e = document.getElementById("des");
- var selected_stop = e.options[e.selectedIndex].text;
- </script>
- <table>
- <thead>
- <tr>
- <th>Route_No</th>
- <th>Bus_Name</th>
- <th>Fare</th>
- </tr>
- </thead>
- <tbody>
- <?php
- $host="localhost";
- $user="root";
- $password="";
- $db="transport_system";
- $link = mysqli_connect($host,$user,$password,$db);
- //echo "Before Assigning: <script>document.write(selected_stop)</script><br>";
- $sel_dest = (string)"<script>document.write(selected_stop)</script>";
- //$r = "route";
- //$sl_dest = (string)$sel_dest;
- echo "$sel_dest";
- $sel_dest = "Mohammadpur";
- $route_no=array();
- $bus_names=array();
- $bus_name_sql="SELECT * FROM route AS r JOIN stops AS s ON r.Route_No=s.Route_no WHERE s.Stop_name='$sel_dest';";
- $result = mysqli_query($link,$bus_name_sql) or die(mysqli_error($link));
- $noOfData = mysqli_num_rows($result);
- //echo "$noOfData";
- while($row = mysqli_fetch_row($result)){
- $route_no[]=$row[0];
- $bus_names[]=$row[2];
- //echo "$row[2]";
- }
- //-------------------Convertng array to string here-----------------
- $mega_holder = implode("|", $bus_names);
- $chunks = explode("," , $mega_holder);
- //echo "$chunks[0]";
- //echo "$chunks[1]";
- ?>
- <?php foreach($chunks as $x){ ?>
- <tr>
- <td><?php echo $route_no[0]?></td>
- <td><?php echo $x?></td>
- <td><?php
- //$link = mysqli_connect($host,$user,$password,$db);
- $temp_arr = array();
- $fare_query = "SELECT * FROM bus_company WHERE Company_name LIKE '$x';";
- $fare_result = mysqli_query($link, $fare_query) or die(mysqli_error($link));
- $query_row = mysqli_num_rows($fare_result);
- //echo "$query_row";
- while($row = mysqli_fetch_row($fare_result)){
- $temp_arr[]=$row[2];
- }
- //echo "$temp_arr[0]";
- $fare_str = implode("|", $temp_arr);
- $fare_chunks = explode(",", $fare_str);
- //echo "$fare_str";
- $total = 0;
- foreach($fare_chunks as $x){
- $temp = (int)$x;
- $total = $total + $temp;
- //echo "$total";
- }
- echo "$total";
- ?></td>
- </tr>
- <?php } ?>
- </tbody>
- </table>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement