我正在创建购物网站,现在我有一个表调用产品,所有的产品数据都存储在其中,我有不同的表购物车,其中所有的产品都被添加到购物车中,所以基本上在购物车中我存储了productid,userid所以现在在checkout页面上,我想从cart表中检索数据,我们将获取特定登录用户的productid,从表products中我们将显示添加到cart的所有产品,因此基本上从cart表中我们将获取添加到cart的产品,从表products中我们将显示它们。现在的问题是,我检索到的数据,但它只显示一个项目,而不是多个。提前谢谢
这是我的密码:
<?php $userid = $_SESSION['userSession'];
require_once 'dbconfig.php';
$stmt = $DB_con->prepare('SELECT cartid,userid,productid FROM cart WHERE userid =:uid');
$stmt->execute(array(':uid'=>$userid));
if($stmt->rowCount() > 0)
{
while($rows=$stmt->fetch(PDO::FETCH_ASSOC))
{
extract($rows);
{
}
?>
<?php
$productid = $rows['productid'];
require_once 'dbconfig.php';
$stmt = $DB_con->prepare('SELECT productid,productname,productcategory,producttype,productprice,productimage1 FROM products WHERE productid = :uid');
$stmt->execute(array(':uid'=>$productid));
if($stmt->rowCount() > 0)
{
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
extract($row);
{
}
?>
<div class="bs-example4" data-example-id="simple-responsive-table">
<div class="table-responsive">
<table class="table-heading simpleCart_shelfItem">
<tr>
<th class="table-grid">Item</th>
<th>Prices<h3></h3></th>
<th >Delivery </th>
<th>Subtotal</th>
</tr>
<tr class="cart-header1">
<td class="ring-in"><a href="single.html" class="at-in"><img src="thumb/<?php echo $row['productimage1']; ?>" class="img-responsive" alt=""></a>
<div class="sed">
<h5><a href="single.html"><?php echo $row['productname']; ?></a></h5>
</div>
<div class="clearfix"> </div>
<div class="close2"> </div></td>
<td>₹ <?php echo $row['productprice']; ?></td>
<td>FREE SHIPPING</td>
<td class="item_price">$100.00</td>
<td class="add-check"><a class="item_add hvr-skew-backward" href="#">Add To Cart</a></td>
</tr>
</table>
</div>
</div>
<div class="produced">
<a href="single.html" class="hvr-skew-backward">Produced To Buy</a>
</div>
</div>
</div>
<?php
}
}
else
{
?>
<div class="col-xs-12">
<div class="alert alert-warning">
<span class="glyphicon glyphicon-info-sign"></span> No Data Found ...
</div>
</div>
<?php
}
?> <?php
}
}
else
{
?>
<div class="col-xs-12">
<div class="alert alert-warning">
<span class="glyphicon glyphicon-info-sign"></span> No Data Found ...
</div>
</div>
<?php
}
?>
3条答案
按热度按时间z9gpfhce1#
我要加上这个技巧,它更接近于我所用的,没有其他人做得完全一样。
sdnqo3pr2#
可以使用一个使用内部联接的查询
2j4z5cfb3#
您应该对join语句使用另一个且只能使用一个查询。
您将收到的数据将包含来自购物车的产品数据。