Php Magento获得产品
我的Magento中有一个网站,我想在那里进行自定义查询。 我的查询没有问题(我已经在phpmyadmin中尝试过) 我已经在我的文件.phtml中尝试了这段代码Php Magento获得产品,php,magento,Php,Magento,我的Magento中有一个网站,我想在那里进行自定义查询。 我的查询没有问题(我已经在phpmyadmin中尝试过) 我已经在我的文件.phtml中尝试了这段代码 <?php // fetch write database connection that is used in Mage_Core module $db = Mage::getSingleton('core/resource')->getConnection('core_read'); $result = $db->
<?php
// fetch write database connection that is used in Mage_Core module
$db = Mage::getSingleton('core/resource')->getConnection('core_read');
$result = $db->query("select * from catalog_product_flat_1 WHERE short_description LIKE '%".$description_search."%' AND entity_id != ".$product_id." ;");
//After running check whether data is available or not
if(!$result) {
echo 'No data found';
}
else
{
//Here we are fetching the data
echo('<p>here '.$result->fetchAll(PDO::FETCH_ASSOC).'</p>');
foreach ($result->fetchAll() as $row)
{
echo ('<p><br>Name: </p>');
}
}
有了这个var_dump,我就有了对象,例如:
object(Varien_Db_Statement_Pdo_Mysql)#631 (9) { ["_fetchMode":protected]=> int(2) ["_stmt":protected]=> object(PDOStatement)#572 (1) { ["queryString"]=> string(130) "select * from catalog_product_flat_1 WHERE short_description LIKE '%Riferimento originale: TN-1700%' AND entity_id != 733536 ;" } ["_adapter":protected]=> object(Varien_Db_Adapter_Pdo_Mysql)#14 (30) { ["_defaultStmtClass":protected]=> string(29) "Varien_Db_Statement_Pdo_Mysql" ["_transactionLevel":protected]=> int(0) ["_connectionFlagsSet":protected]=> bool(true) ["_ddlCache":protected]=> array(1) { [1]=> array(4) { ["eav_attribute"]=> array(17) { ["attribute_id"]=> array(14) { ["SCHEMA_NAME"]=> NULL....
如何正确检索我的产品?下面的代码是否适用于您
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*')
->addFieldtoFilter('short_description', array('like' =>'%Good Luck%'))
->addFieldtoFilter('entity_id', array('eq' => 404));
然后你可以得到现场数据,比如
foreach($collection as $row){
echo $row->getName();
}
将错误返回到“选择我必须从目录\u产品\u平面\u 1检索数据”中
foreach($collection as $row){
echo $row->getName();
}