dskpywvki951583595 2013-07-08 09:01
浏览 13
已采纳

Magento获得产品

I have a site into my Magento where I want to make a custom query. My query is ok (I have tried it into phpmyadmin)

I have tried this code into my file .phtml

<?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>');
    }
}

Into the foreach doesn't print anything and the fetchAll is empty. But if I make:

var_dump($result);

With this var_dump I have the object for example:

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

How can I retrieve correctly my product?

  • 写回答

1条回答 默认 最新

  • doulan9419 2013-07-08 09:28
    关注

    may below code work for you

    $collection = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToSelect('*')
    ->addFieldtoFilter('short_description', array('like' =>'%Good Luck%'))
    ->addFieldtoFilter('entity_id', array('eq' => 404));
    

    and then you can get field data like

    foreach($collection as $row){
    echo $row->getName();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测