2013-07-08 251 views
0

我有一個網站到我想要做自定義查詢的我的Magento。 我的查詢就可以了(我已經嘗試過進入phpMyAdmin的)Magento獲得產品

我曾嘗試這個代碼到我的文件一個.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>'); 
    } 
} 

進的foreach不顯示任何信息和使用fetchall是空的。 但是,如果我做:

var_dump($result); 

有了這個的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.... 

我怎樣才能正確地獲取我的產品?

回答

2

可能低於你

$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(); 
} 
+0

返回錯誤字段數據到選擇我要檢索catalog_product_flat_1數據 –