gpt4 book ai didi

php - 如何使用php滚动电子商务网站中的相关项目

转载 作者:行者123 更新时间:2023-11-29 01:54:47 24 4
gpt4 key购买 nike

我正在使用 PHP 创建一个电子商务网站。我有产品页面(product.php),在该页面中我需要根据类别滚动相关项目。我做了所有的事情,但相关的项目重复了两次(我的意思是一个项目来了两次,但我只想要一次)。

我的代码如下:

    // 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-->

最佳答案

您正在执行相同的查询两次,这就是为什么您列出两次的产品只使用一个,例如:

<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-->

并且看起来您试图将两个 div 与两个不同的类组合在一起,那么首先您需要确定需要隔离的点。

关于php - 如何使用php滚动电子商务网站中的相关项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32224057/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com