如果沒有從MySQL返回的行,我想隱藏類「產品列表」中的div。 我與DIV代碼如下:隱藏div,如果沒有從while循環返回的行PHP
$sql_product = "select * from `product_detail`";
$result_product = $this->db->query($sql_product);
<div class="table-responsive product-list">
<h5>Product Detail</h5>
<table class="table table-striped">
<thead>
<tr>
<th>Product Name</th>
<th>Quantity</th>
<th>MRP</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<?php
while($row = mysqli_fetch_array($result_product)){
$product_name = $row['product_name'];
$category_name = $row['category_name'];
$quantity = $row['quantity'];
$product_mrp = $row['mrp'];
$amount = $row['amount'];
?>
<tr>
<th><?php echo $category_name; ?>/<?php echo $product_name; ?></th>
<th><?php echo $quantity; ?></th>
<th><?php echo $product_mrp; ?></th>
<th><?php echo $amount; ?></th>
</tr>
<?php } ?>
</tbody>
</table>
</div>
http://php.net/manual/en/control-structures.if.php – Scuzzy 2015-04-02 13:42:43
我已經嘗試了條件,但如何使用while循環中聲明的變量? – 2015-04-02 13:46:21
然後告訴我們'if/else' – 2015-04-02 13:48:52