【发布时间】:2016-10-25 07:58:19
【问题描述】:
基本上,我有一个从 mysqli 迭代的类别列表
<div style="width:20%; float:left;">
<h3>Categories</h3>
<?php while($categories = $resultproductcategories->fetch_assoc()){?>
<div class="rows">
<input type="button" name="<?php echo $categories['id'] ?>" value="<?php echo $categories['category?>" />;
</div>
<?php }?>
</div>
现在我想要的是,如果我按任何类别,它应该相应地获取数据,这是我的获取代码
$stmtproducts = $mysqli->prepare("SELECT * FROM store_products sp INNER JOIN store_product_categories spc ON sp.product_category=spc.id WHERE sp.store_id=? AND sp.category=? LIMIT $count, 10");
$stmtproducts->bind_param("ii",$_SESSION['storeid'],$_POST['']);
$stmtproducts->execute();
$resultproducts = $stmtproducts->get_result();
$num=$resultproducts->num_rows;
echo $num;
$stmtproducts->close();
我很困惑,如果有一个特定的输入名称,那么我会通过isset($_POST['name']) 得到它,但是没有特定的名称......我想不出如何将类别发送到 mysql。
<div id="divTransactional" style="width:70%;padding-left:5%; float:left;">
<?php if($num>0) {?>
<table class="table table-responsive table-hover" id="tableProducts">
<h3>Products</h3>
<tbody>
<?php for($i=0;$i<$num;$i++) { $products = $resultproducts->fetch_assoc();//while($products = $resultproducts->fetch_assoc()) {?>
<tr>
<td>Code: <?php echo $products['product_code'];?></td><td>Added On: <?php echo $products['product_date'];?></td>
</tr>
<tr>
<td>Name: <?php echo $products['product_name'];?></td>
</tr>
<tr>
<td>Category: <?php echo $products['category'];?></td>
</tr>
<tr>
<td>Description: <?php echo $products['product_desc'];?></td>
</tr>
<tr>
<td>Price: <?php echo $products['product_price'];?></td><td>Discount: <?php echo $products['product_discount'];?></td>
</tr>
<tr style="width:100px; height:100px;">
<td><img src="../../uploads/store/products/<?php echo $products['product_image1'];?>" style="width:100px; height:100px;"/></td>
<td><img src="../../uploads/store/products/<?php echo $products['product_image2'];?>" style="width:100px; height:100px;"/></td>
<td><img src="../../uploads/store/products/<?php echo $products['product_image3'];?>" style="width:100px; height:100px;"/></td>
<td><img src="../../uploads/store/products/<?php echo $products['product_image4'];?>" style="width:100px; height:100px;"/></td>
</tr>
<?php }?>
</tbody>
<?php if($num >= 10) { ?>
<a href="<?php echo $_SERVER['PHP_SELF'].'?count='.($count+10)?>">Next</a>
<?php } ?>
<?php $prev = $count - 10;
if ($prev >= 0){?>
<a href=" <?php echo $_SERVER['PHP_SELF'].'?count='.$prev ?>">Previous</a>
<?php }?>
</table>
<?php if($num >= 10) { ?>
<a href="<?php echo $_SERVER['PHP_SELF'].'?count='.($count+10)?>">Next</a>
<?php } ?>
<?php $prev = $count - 10;
if ($prev >= 0){?>
<a href=" <?php echo $_SERVER['PHP_SELF'].'?count='.$prev ?>">Previous</a>
<?php }?>
<?php } ?>
</div>
【问题讨论】:
-
你想显示数据还是从服务器获取数据?
-
从服务器获取它...假设有两个类别迭代... category1 和 category2...当我单击 category1 时,应该只获取 category1 数据
-
我建议使用 ajax。
-
你熟悉javascript和JQuery吗?
-
不多,但我也希望在 url 上附加类别!