<?php  
 //filter.php  
 if(isset($_POST["from_date"], $_POST["to_date"]))  
 {  
      include("conn.php");
      $output = '';      

      $query = "SELECT i.Item_ID, i.Item_Name, i.Item_Price, SUM(od.Order_Amount) FROM online_ordering_details od, online_ordering oo, item i WHERE (od.Order_ID = oo.Order_ID) AND (od.Item_ID = i.Item_ID) AND (oo.Order_Date BETWEEN '".$_POST["from_date"]."' AND '".$_POST["to_date"]."') GROUP BY i.Item_ID ";
      $result = mysqli_query($conn, $query);  
      $output .= '  
          <h3 style="color:orange;margin-top:15px;">Online Sales</h3> 
          <table class="table">
               <thead class="thead-dark">
                    <tr>
                        <th>Item ID</th>
                        <th>Item Name</th>
                        <th>Price</th>
                        <th>Online Sold</th>
                        <th>Total Revenue</th>
                    </tr>
               </thead>  
     ';  
     if(mysqli_num_rows($result) > 0)  
     {  
          while($row = mysqli_fetch_array($result))  
          {  
               $output .= '  
                    <tbody>
                        <tr>
                            <td>'. $row["Item_ID"] .'</td>
                            <td>'. $row["Item_Name"] .'</td>
                            <td>RM '. $row["Item_Price"] .'</td>
                            <td>'. $row["SUM(od.Order_Amount)"] .'</td>
                            <td>RM '. $row["Item_Price"] * $row["SUM(od.Order_Amount)"] .'</td>
                        </tr>
                    </tbody> 
               ';  
          }  
     }  
     else  
     {  
          $output .= '  
               <tr>  
                    <td colspan="5">No Items Sold Online Found!</td>  
               </tr>  
          ';  
     }  
     $output .= '</table>';  
     echo $output;  
}  
?>