【发布时间】:2015-08-29 22:33:02
【问题描述】:
我在一家在线商店工作,在尝试检索产品颜色并在 Html 复选框中向用户显示时遇到了一个大问题。我在我的数据库中插入了四个字段,并将它们设置为变量 $pro_one、$pro_two、$pro_three、$pro_four强>。但问题是某些产品只有两种颜色,例如,我不希望页面显示其他 2 个复选框。为此,我需要编写一个 If else 语句 来检查 phpmyadmin 中的字段,以查看每个字段是否不为空,显示它,否则不显示它。所以,如果你知道如何做到这一点,请帮助我,我真的很感激!谢谢...
<?php
if (isset($_GET['pro_id'])){
$product_id = $_GET['pro_id'];
$get_pro = "select * from products where product_id='$product_id'";
$run_pro = mysqli_query($con,$get_pro);
while($row_pro = mysqli_fetch_array($run_pro)){
$pro_id = $row_pro['product_id'];
$pro_cat = $row_pro['product_cat'];
$pro_brand = $row_pro['product_brand'];
$pro_title = $row_pro['product_title'];
$pro_price = $row_pro['product_price'];
$pro_image = $row_pro['product_image'];
$pro_desc = $row_pro['product_desc'];
$pro_key = $row_pro['product_keywords'];
$pro_date = $row_pro['date_added'];
$pro_ava = $row_pro['input_ava'];
$pro_rate = $row_pro['site_rate'];
$pro_rev = $row_pro['product_review'];
$pro_plast = $row_pro['last_price'];
$pro_warran = $row_pro['product_warranty'];
$pro_pre = $row_pro['gooya_present'];
$pro_colors = $row_pro['ava_colors'];
$pro_one = $row_pro['color_one'];
$pro_two = $row_pro['color_two'];
$pro_three = $row_pro['color_three'];
$pro_four = $row_pro['color_four'];
echo "<form id='submittion'>
<label style='font-family: BMehrBold, Arial, Helvetica, sans-serif;'>Quantity:</label>
<input type='text' value='1' /></br></br>
<table style='margin-bottom:10px;width: 100%;'>
<tr>
<td><input type='checkbox' name='colour' checked></td>
<td><input type='checkbox' name='colour'></td>
<td><input type='checkbox' name='colour'></td>
<td><input type='checkbox' name='colour'></td>
</tr>
<tr>
<td><p style='font-family: BMehrBold, Arial, Helvetica, sans-serif;'>$pro_one</p></td>
<td><p style='font-family: BMehrBold, Arial, Helvetica, sans-serif;'>$pro_two</p></td>
<td><p style='font-family: BMehrBold, Arial, Helvetica, sans-serif;'>$pro_three</p></td>
<td><p style='font-family: BMehrBold, Arial, Helvetica, sans-serif;'>$pro_four</p></td>
</tr>
</table>
<button type='button' class='btn btn-fefault cart'>
<i class='fa fa-shopping-cart' ></i>
Add to cart
</button></br>
</form>";
?>
【问题讨论】:
标签: php html mysql phpmyadmin