Jump to content

result does not show in tables


sashavalentina
 Share

Recommended Posts

I want to make display my data into tables but why does it not shown in the table? the total results shown 1 but i only got no data display in my table. Can i know what is wrong in my code? Is there any mistake in my query?

<?php
            $category = $_REQUEST['catid'];
            $month = $_REQUEST['month'];
            $sellerid = $_REQUEST['sellerid'];
            
            $sql = "SELECT  o.order_id , o.purchase_price , u.id, u.user_fullname ,  p.id, p.product_title , c.id , c.category, s.id , s.seller_fullname FROM ordered_items o INNER JOIN users u ON o.user_id = u.id INNER JOIN sellers s ON o.seller_id = s.id 
            INNER JOIN products p ON o.product_id = p.id CROSS JOIN category c ON p.product_category = c.id WHERE category = '".$category."' GROUP BY p.id ";
            $query = $conn->query($sql);
            $tot_orders = mysqli_num_rows($query);
            if (!mysqli_num_rows($query)) {
              echo '
                <div class="col-12">
                  <div class="badge badge-danger">No Orders Found</div>
                </div>
              ';
            } else {
              while ($row = $query->fetch_assoc()) {
                ?>

          <div class="col-12">
            <div class="card">

              <div class="card-header">
                <h4 class="card-title"> Report for category: <b> <?php echo $category ?> </b> ( <?php echo $month ?> ) from seller: <b> <?php echo $row['seller_fullname']; ?> </b></h4> 
                 <b class="float-left mb-4">Total Records: <?php echo $tot_orders; ?></b>
              </div>
                <div class="table-responsive" style="max-height: 70vh">
                  <table class="table">
                    <thead class="text-primary">
                      <th style=" position: sticky;top: 0; background: white";>
                        Order Id
                      </th>
                      <th style=" position: sticky;top: 0; background: white";>
                        User Name
                      </th>
                      <th style=" position: sticky;top: 0; background: white";>
                        Total Purchase
                      </th>
                      <th class="text-center" style=" position: sticky;top: 0; background: white";>
                        Action
                      </th>
                       
                    </thead>
                    <tbody>
                      <?php
                      if (!$tot_orders) {
                        echo '
                          <tr>
                            <td colspan="8" class="badge badge-danger">Nothing Found</td>
                          </tr>
                        ';
                      } else {
                         while ($row = $query->fetch_assoc()) {
                       
                         
                      ?>
                      <tr>
                        <td>
                          #<?php echo $row['order_id']; ?>
                        </td>
                        <td>
                          <?php echo $row['user_fullname']; ?>
                        </td>
                        <td>
                          RM<?php echo  number_format($row['purchase_price'],2); ?>
                        </td>
                      
                      </tr>
 </div>
          
            </div>
          </div>
    <?php
    
    }
    }
    }
    }
    
    ?>

This is the result i got from my tables.There should be one data shown in the table when the Total Records:1. I do not know what mistake i did here. the result always display to be lack of one data from the Total Records

image.png.5ef26560d5260689177388151c0a0843.png

 

Link to comment
Share on other sites

33 minutes ago, sashavalentina said:

} else {

while ($row = $query->fetch_assoc()) {

all you have done is replace the single $row = $query->fetch_assoc(); statement with one inside of a while(){} loop. how is that going to make this work?

rather than starting new threads for the same problem, read the reply, on how to correct this, that you have already gotten in the first thread.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.