Am creating a E-Commerce website using PHP. I have product page(product.php), in that page i need to scroll the related items based on categories. I did everything, but related items repeat two times(i mean one item comes two times but i want only once).
My code is following :
// Class "item active"
<div class="item active">
<?php
$select = mysql_query("select * from product where categories ='$categories' limit 4");
while($rows = mysql_fetch_array($select))
{
$p_id = $rows['product_id'];
$p_img = $rows['image'];
$p_color = $rows['color'];
$p_name = $rows['product_name'];
$p_desc = $rows['product_detsils'];
$categories = $rows['categories'];
$p_offer = $rows['offer'];
$p_price = $rows['buying_price'];
?>
<div class="col-sm-3">
<div class="product-image-wrapper">
<div class="single-products">
<div class="productinfo text-center">
<a href="product.php?product_id=<?php echo $p_id; ?>">
<img src="images/product/<?php echo $p_img;?>.jpg" alt="" />
<h2><i class="fa fa-inr"></i> <?php echo $p_price;?></h2>
<p><?php echo $p_name;?></p>
</a>
<button type="button" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Add to cart</button>
</div><!--productinfo text-center end-->
</div><!--single-products-->
</div><!--product-image-wrapper end-->
</div><!--col-sm-3 end-->
<?php } ?>
</div><!--item active end-->
//Classs "item"
<div class="item ">
<?php
$select = mysql_query("select * from product where categories ='$categories' limit 4");
while($rows = mysql_fetch_array($select))
{
$p_id = $rows['product_id'];
$p_img = $rows['image'];
$p_color = $rows['color'];
$p_name = $rows['product_name'];
$p_desc = $rows['product_detsils'];
$categories = $rows['categories'];
$p_offer = $rows['offer'];
$p_price = $rows['buying_price'];
?>
<div class="col-sm-3">
<div class="product-image-wrapper">
<div class="single-products">
<div class="productinfo text-center">
<a href="product.php?product_id=<?php echo $p_id; ?>">
<img src="images/product/<?php echo $p_img;?>.jpg" alt="" />
<h2><i class="fa fa-inr"></i> <?php echo $p_price;?></h2>
<p><?php echo $p_name;?></p>
</a>
<button type="button" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Add to cart</button>
</div><!--productinfo text-center end-->
</div><!--single-products-->
</div><!--product-image-wrapper end-->
</div><!--col-sm-3 end-->
<?php } ?>
</div><!--item end-->