douchenchepan6465 2018-07-14 13:42
浏览 50
已采纳

通过php显示数据时产生的额外空行

I don't know why this code generates an extra row in the last, it only happens when i use PHP to display my data. There's no extra row in table tho. The extra row shows empty data.

 <div class="tbl-header">
<table cellpadding="0" cellspacing="0" border="0">
    <thead>
        <tr>
            <th>ID</th>
            <th>Product Name</th>
            <th>Brand</th>
            <th>Category Name</th>
            <th>Description</th>
            <th>Picture</th>
            <th>Quantity</th>
            <th>Price</th>
        </tr>
        <?php
            $data = mysqli_query($con, "select `shopifyv2`.`products`.`ID` AS `ID`,`shopifyv2`.`products`.`ProductName` AS `ProductName`,`shopifyv2`.`brands`.`BrandName` AS `BrandName`,`shopifyv2`.`category`.`Name` AS `CategoryName`,`shopifyv2`.`products`.`Description` AS `Description`,`shopifyv2`.`products`.`Picture` AS `Picture`,`shopifyv2`.`products`.`Quantity` AS `Quantity`,`shopifyv2`.`products`.`Price` AS `Price` from `products` join `shopifyv2`.`brands` on `products`.`BrandID` = `brands`.`ID` join `shopifyv2`.`category` on `products`.`CateID` = `category`.`ID`");
            $row = mysqli_num_rows($data);

            for ($i = 0; $i < $row; $i++) {
                $row = mysqli_fetch_array($data);
                echo "<tr>";
                echo "<td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td><td>$row[4]</td><td><img height='30' width='20' src='../AdminPanel/Pictures/$row[5]'/ /></td><td>$row[6]</td><td>$row[7]</td>";
                echo "<td><a href='ModifyProduct.php?ID=$row[0]' class='btn btn-info'>Modify</a></td>";
                echo "<td><a href='ShowProduct.php?id=$row[0]'>Delete</a></td>";
                echo "</tr>";
            }
            if (isset($_GET['id'])) {
                $delid = $_GET['id'];
                mysqli_query($con, "delete from products where id = $delid");
                header("location: ShowProduct.php");
            }
        ?>
    </thead>
</table>

  • 写回答

1条回答 默认 最新

  • duanbi7247 2018-07-14 15:17
    关注

    You might check if the row is not empty:

    $row = mysqli_num_rows($data);
    
    for ($i = 0; $i < $row; $i++) {
       $row = mysqli_fetch_array($data);
       if(!$row[0]) continue; // <- HERE
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度