gpt4 book ai didi

php - Magento PHP SQL 查询从特定类别(包括 child )中提取产品

转载 作者:行者123 更新时间:2023-11-29 14:18:56 25 4
gpt4 key购买 nike

我目前正处于紧要关头,需要对我网站上的一些现有代码进行调整。有一个 PHP SQL 查询需要修改以从特定类别中提取产品。然后将该列表输入到 HTML 产品轮播中。无论如何,目前它正在拉取所有带有图像的产品。

<?php
$query = mysql_query("SELECT * FROM `catalog_product_flat_1` WHERE `small_image` != 'no_selection'");
//$query = mysql_query("SELECT * FROM `catalog_product_flat_1` WHERE `category_ID` = 16");
while($fins = mysql_fetch_array($query)) {
?>

注释的代码行是我试图做的,但没有运气。我在这里在黑暗中拍摄。从任何标准来看,我都不是 Magento 或 PHP 专家。仅供引用,前端显示我想要的类别的类别 ID 为 16。按名称提取它会很好,但为了简单/速度起见,我可以使用 ID。

感谢您的帮助。

(更新8-27)整个 HTML 代码块:

<div class="whiteGradientLarge span-10">
<div class="content">
<h2>Latest Products</h2>
<div class="span-10">
<a href="#" class="prev left"><img src="assets/arrowPrev.png" /></a>
<ul class="productSlider push-1">

<?php
//$query = mysql_query("SELECT * FROM `catalog_product_flat_1` WHERE `small_image` != 'no_selection'");
//while($products = mysql_fetch_array($query)) {
$category = new Mage_Catalog_Model_Category();
$category->load('16'); //your category id here, 16 $catid
$prodCollection = $category->getProductCollection();
foreach ($prodCollection as $product) {
//get all the product information here... //}
?>
<li class="roundabout-moveable-item">
<h3><a href="http://www.mywebsite.com/store/products/<?php echo $product['url_path']; ?>"><?php echo $product['name']; ?></a></h3>
<img src="https://www.mywebsite.com/store/media/catalog/product<?php echo $product['small_image']; ?>" />
<span class="productTitle span-3"><?php ?></span>
</li>
<?php
} ?>
</ul>
<a href="#" class="next right"><img src="assets/arrowNext.png" /></a>
</div>
</div>

</div>

最佳答案

$category = new Mage_Catalog_Model_Category();
$category->load($catid); //your category id here, 16
$prodCollection = $category->getProductCollection();
foreach ($prodCollection as $product) {
//get all the product information here...

?>
<li class="roundabout-moveable-item">
<h3><a href="http://www.mywebsite.com/store/products/<?php echo $product->getUrlPath(); ?>"><?php echo $product->getName(); ?></a></h3>
<img src="https://www.mywebsite.com/store/media/catalog/product<?php echo $product->getSmallImage(); ?>" />
<span class="productTitle span-3"><?php ?></span>
</li>
<?php
}

关于php - Magento PHP SQL 查询从特定类别(包括 child )中提取产品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12093858/

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