Home » Php » mysql – Translating sql query to table with php

mysql – Translating sql query to table with php

Posted by: admin February 25, 2020 Leave a comment

Questions:

I need in translating my sql query in this table format

enter image description here

<div class="table-responsive">
                <table id="example1" class="table table-bordered table-striped">

                	<tbody>
                		<tr>
                			<td colspan="3" style="text-align:cneter;">
                        School Name<br/>
                        Summary Expenditure Report For Month
                      </td>
                		</tr>
                    <?php
                      $total="";
                      $sql = "SELECT a.category, b.description, c.amount,c.income_date FROM ((oystirev_category a INNER JOIN oystirev_category_income b ON b.main_cat_id = a.id) INNER JOIN oystirev_income c ON c.item_id = b.id) WHERE c.school_id='".$_SESSION['id']."'";
                      $category_row = query($sql);
                      while($row = fetch_array($category_row)){
                        //  $main_category .=;

                    ?>
                		<tr>
                			<td colspan="3" ><?php echo $row['category']; ?> </td>
                		</tr>

                		<tr>
                      <td> SN</td>
                			<td><?php echo $row['description']; ?> </td>
                			<td> <?php echo $row['amount']; ?> </td>
                		</tr>
                    <?php
                      $total+=$row['amount'];
                      //  $sql2 = "SELECT a.description,a.main_cat_id FROM oystirev_category_income a,oystirev_category b WHERE a.main_cat_id=b.id a.school_id='".$_SESSION['id']."'";
                      //  $sub_row = query($sql2);
                      //  while($rowsub = fetch_array($sub_row)){
                     ?>
                		<tr>
                      <td></td>
                			<td>Sub Total </td>
                			<td> <?php // echo $total; ?></td>
                		</tr>
                    <?php
                      //  }
                      }
                     ?>
                    <tr>
                      <td></td>
                      <td>Grand Total </td>
                      <td> amount</td>
                    </tr>
                	</tbody>

                </table>
              </div>
              <!-- /.table-responsive -->
            </div>
How to&Answers:
<div class="table-responsive">
            <table id="example1" class="table table-bordered table-striped">
                <tr>
                    <td colspan="3" style="text-align:cneter;">
                        School Name<br/>
                        Summary Expenditure Report For Month
                    </td>
                </tr>
                <?php //start of the category loop?> 
                <?php $total=0; // here request to select the categories;?> 

                <tr>
                    <td>SN</td>
                    <td colspan="1" ><?php //displays the name of the category ?></td>
                </tr>
                <?php //start of the product loop?>
                <?php //the query to select the products of the category?> 

                <?php $Subtotal=0; $i
                    $sql1 = "SELECT a.category, b.description, c.amount,c.income_date FROM ((oystirev_category a INNER JOIN oystirev_category_income b ON b.main_cat_id = a.id) INNER JOIN oystirev_income c ON c.item_id = b.id) WHERE c.school_id='".$_SESSION['id']."'";
                    $category_row = query($sql1);
                    while($row = fetch_array($category_row)){
                ?>

                <tr>
                    <td><?php echo $i; ?> </td>
                    <td><?php echo $row['description']; ?> /td>
                    <td><?php echo $row['amount']; ?><</td>
                </tr>
                <?php $i++; }?>
                <?php //end of the product loop?>
                <tr>
                    <td></td>
                    <td >Sub Total</td>
                    <td>  <?php  echo $Subtotal+=$row['amount']; $total+=$Subtotal?></td>
                </tr>
                <?php //end of the category loop?> 

                <tr>
                    <td colspan="1">Sub Total</td>
                    <td>  <?php  echo $total; ?></td>
                </tr>
            </table>
          </div>
          <!-- /.table-responsive -->
        </div>