<?php  
 //filter.php  
 if(isset($_POST["from_date"], $_POST["to_date"]))  
 {  
      include("conn.php");
      $output = '';  
      $query = "SELECT bc.Court_ID, b.Court_Name, b.Court_Rental_Rate, SUM(bc.Duration) 
      FROM futsal_court_booking bc, futsal_court b 
      WHERE (bc.Court_ID = b.Court_ID) AND (bc.Start_Time BETWEEN '".$_POST["from_date"]."' AND '".$_POST["to_date"]."')  GROUP BY bc.Court_ID"; 
      
      $result = mysqli_query($conn, $query);  
      $output .= '  
          <h3 style="color:orange;margin-top:15px;">Futsal Court</h3> 
          <table class="table">
                <thead class="thead-dark">
                    <tr>
                        <th>Court ID</th>
                        <th>Court Name</th>
                        <th>Rental Rate</th>
                        <th>Total Duration (Hour)</th>
                        <th>Total Revenue</th>
                    </tr>
                </thead>  
      ';  
      if(mysqli_num_rows($result) > 0)  
      {  
           while($row = mysqli_fetch_array($result))  
           {  
                $output .= '  
                    <tbody>
                        <tr>
                            <td>'. $row["Court_ID"] .'</td>
                            <td>'. $row["Court_Name"] .'</td>
                            <td>RM '. $row["Court_Rental_Rate"] .'</td>
                            <td>'. $row["SUM(bc.Duration)"] .'</td>
                            <td>RM '. $row["Court_Rental_Rate"] * $row["SUM(bc.Duration)"] .'</td>
                        </tr>
                    </tbody> 
                ';  
           }  
      }  
      else  
      {  
           $output .= '  
                <tr>  
                     <td colspan="5">No Booking Completed Found!</td>  
                </tr>  
           ';  
      }  
      $output .= '</table>';  
      echo $output;  
 }  
 ?>