0

how to get single row data. this code is retrieving all data in table.

$connectionresource = Mage::getSingleton('core/resource');   
$readconnection = $connectionresource->getConnection('core_read'); 

$allrecord = $readconnection->select()->from(array('customimgupload'=>'customimgupload'));

$alldata =$readconnection->fetchAll($allrecord);

foreach($alldata as $img)
   {
     echo $img['image_url'];?><br/><?php 
   }

?>
1
  • Your question is not clear
    – Asish Hira
    Apr 4, 2016 at 11:27

2 Answers 2

1

add limit it will show the single record ->limit(1, 1)

$pro_id=10;// add your desired product id
$connectionresource = Mage::getSingleton('core/resource');   
$readconnection = $connectionresource->getConnection('core_read'); 

$allrecord = $readconnection->select()->from(array('customimgupload'=>'customimgupload'))->where('customimgupload.product_id=?', $pro_id);

$alldata =$readconnection->fetchRow($allrecord);

 echo $alldata['image_url'];?><br/><?php 
28
  • I want to load product id and get that particular image
    – Magento 2
    Apr 4, 2016 at 11:48
  • what you column name for product id? Apr 4, 2016 at 11:49
  • product_id......
    – Magento 2
    Apr 4, 2016 at 11:50
  • Call to a member function select() on a non-object
    – Magento 2
    Apr 4, 2016 at 11:57
  • updated the code try it Apr 4, 2016 at 12:03
1

Use fetchRow instead of fetchAll

2
  • fetchOne returns a single value not array. Instead of fetchRow is correct it return array. Apr 4, 2016 at 12:26
  • 1
    Right. I was looking in the wrong adapter. Thanks.
    – Marius
    Apr 4, 2016 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.