I am creating shopping website now i have one table call products in which all the products data is stored and i have different table cart in which all the product which are added to cart are stored so basically in cart I have stored productid, userid so now on page called checkout I want to retrieve data in which the data from cart table we will take productid of particular logged in user and from the table products we will show all the product added to cart so basically from cart table we will take the product added to cart and from table products we will show them . now the problem is that i have retrieved the data but it only showing one item and not multiple. Thanks in advance
Here is my code:
<?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
}
?>
You should use another and only one query with JOIN statement.
SELECT * FROM cart c JOIN products p ON p.productid = c.productid WHERE c.userid = :uid
The data you will receive will contains products data from cart.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments