Advertisement
Guest User

Home

a guest
Dec 29th, 2018
1,161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.94 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3.     <head>
  4.         <meta charset="utf-8">
  5.         <title>Untitled Document</title>
  6.         <link rel="stylesheet" href="home_styler.css">
  7.         <link rel="stylesheet" href="table_styler_common.css">
  8.        
  9.     </head>
  10.  
  11.     <body>
  12.         <div class="header">
  13.             <h1>Welcome!!!!</h1>
  14.         </div>
  15.        
  16.        
  17.         <div id="main">
  18.             <label >Destination </label>
  19.  
  20.             <select name="Des" id="des" class="form-control" onChange="admSelectCheck()">
  21.  
  22.             <?php
  23.                 $host="localhost";
  24.                 $user="root";
  25.                 $password="";
  26.                 $db="transport_system";
  27.  
  28.                 $link = mysqli_connect($host,$user,$password,$db);
  29.  
  30.                 $stop_name=array();
  31.  
  32.                 $bus_name_sql="SELECT Stop_name FROM stops";
  33.  
  34.                 $result = mysqli_query($link,$bus_name_sql) or die(mysqli_error($link));
  35.  
  36.                 $noOfData = mysqli_num_rows($result);
  37.                 while($row = mysqli_fetch_row($result)){
  38.                     $stop_name[]=$row[0];
  39.  
  40.  
  41.                 }
  42.             ?>
  43.  
  44.                 <?php for($i=0;$i<$noOfData;$i++){ ?>
  45.                     <option selected><?php echo $stop_name[$i]?></option>
  46.  
  47.                 <?php } ?>
  48.             </select>
  49.              
  50.            
  51.         </div>
  52.        
  53.         <script>
  54.                 function admSelectCheck(){
  55.                     var e = document.getElementById("des");
  56.                     var selected_stop = e.options[e.selectedIndex].text;
  57.                     //document.getElementById("bus_names").style.display = "block";
  58.                     <?php
  59.                         //$sel_dest = "<script>document.write(selected_stop)</script>";
  60.                         //echo "$sel_dest";
  61.                     ?>
  62.                 }
  63.         </script>
  64.        
  65.         <div id="bus_names">
  66.             <script>
  67.                 var e = document.getElementById("des");
  68.                 var selected_stop = e.options[e.selectedIndex].text;
  69.             </script>
  70.             <table>
  71.                 <thead>
  72.                   <tr>
  73.                     <th>Route_No</th>
  74.                     <th>Bus_Name</th>
  75.                     <th>Fare</th>
  76.                    
  77.                   </tr>
  78.                 </thead>
  79.                 <tbody>
  80.                 <?php
  81.                         $host="localhost";
  82.                         $user="root";
  83.                         $password="";
  84.                         $db="transport_system";
  85.                    
  86.                
  87.                     $link = mysqli_connect($host,$user,$password,$db);
  88.                     //echo "Before Assigning: <script>document.write(selected_stop)</script><br>";
  89.                     $sel_dest = (string)"<script>document.write(selected_stop)</script>";
  90.                     //$r = "route";
  91.                     //$sl_dest = (string)$sel_dest;
  92.                     echo "$sel_dest";
  93.                     $sel_dest = "Mohammadpur";
  94.                    
  95.                     $route_no=array();
  96.                     $bus_names=array();
  97.                     $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';";
  98.  
  99.                     $result = mysqli_query($link,$bus_name_sql) or die(mysqli_error($link));
  100.  
  101.                     $noOfData = mysqli_num_rows($result);
  102.                     //echo "$noOfData";
  103.                     while($row = mysqli_fetch_row($result)){
  104.                         $route_no[]=$row[0];
  105.                         $bus_names[]=$row[2];
  106.                         //echo "$row[2]";
  107.  
  108.                     }
  109.                    
  110.                     //-------------------Convertng array to string here-----------------
  111.                     $mega_holder = implode("|", $bus_names);
  112.                     $chunks = explode("," , $mega_holder);
  113.                     //echo "$chunks[0]";
  114.                     //echo "$chunks[1]";
  115.                    
  116.                 ?>
  117.                
  118.                 <?php foreach($chunks as $x){ ?>
  119.                     <tr>
  120.                         <td><?php echo $route_no[0]?></td>
  121.                         <td><?php echo $x?></td>
  122.                         <td><?php
  123.                                
  124.                                 //$link = mysqli_connect($host,$user,$password,$db);
  125.                                 $temp_arr = array();
  126.                                 $fare_query = "SELECT * FROM bus_company WHERE Company_name LIKE '$x';";
  127.                                 $fare_result = mysqli_query($link, $fare_query) or die(mysqli_error($link));
  128.                                 $query_row = mysqli_num_rows($fare_result);
  129.                                 //echo "$query_row";
  130.                                 while($row = mysqli_fetch_row($fare_result)){
  131.                                     $temp_arr[]=$row[2];                                   
  132.                                 }
  133.                                 //echo "$temp_arr[0]";
  134.                                 $fare_str = implode("|", $temp_arr);
  135.                                 $fare_chunks = explode(",", $fare_str);
  136.                                 //echo "$fare_str";
  137.                                
  138.                                 $total = 0;
  139.                                 foreach($fare_chunks as $x){
  140.                                     $temp = (int)$x;
  141.                                     $total = $total + $temp;
  142.                                     //echo "$total";
  143.                                 }
  144.                                 echo "$total";
  145.                                
  146.                             ?></td>
  147.                    
  148.                     </tr>
  149.                 <?php } ?>
  150.                
  151.                 </tbody>
  152.             </table>
  153.         </div>
  154.        
  155.  
  156.  
  157.     </body>
  158. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement