sashavalentina Posted April 19, 2021 Share Posted April 19, 2021 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 Quote Link to comment https://forums.phpfreaks.com/topic/312503-result-does-not-show-in-tables/ Share on other sites More sharing options...
mac_gyver Posted April 19, 2021 Share Posted April 19, 2021 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. Quote Link to comment https://forums.phpfreaks.com/topic/312503-result-does-not-show-in-tables/#findComment-1585945 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.