Tuesday 26 April 2011

How to connect database and fetch values to print in phtml page

To connect database and fetch values from tables in magento.

<?php
 $write = Mage::getSingleton('core/resource')->getConnection('core_write');
 $readresult= $write->query("SELECT fieldname FROM tablename" );
 while ($row = $readresult->fetch() )
 {
 $temp[] = $row['feildname'];
 }
?>

<?php
print_r($temp);
?>

1 comment:

  1. Thanks i got excellent information from U.....

    ReplyDelete