0

I am using below code to fetch data from db.

$w = Mage::getSingleton('core/resource')->getConnection('core_read'); 
$table = Mage::getSingleton('core/resource')->getTableName('mymodule/mymodule');

$result = $w->select()
    ->from($table)
    ->where('t_store in(0,?)', Mage::app()->getStore()->getStoreId());

$row = $w->fetchAll($result);

It is giving me an array of array something like below

Array
(
    [t_id] => 4
    [t_store] => 0
    [t_name] => name1
    [t_text] => text1
)
Array
(
    [t_id] => 6
    [t_store] => 0
    [t_name] => name2
    [t_text] => text2
)

But I wanted to have only t_text in my result set something like below

Array
(
    [t_text] => text1
)
Array
(
    [t_text] => text2
)

How can I modify my code or query to have above result set? Any help will be appreciated.

  • try $w->select('t_text'). – Rajeev K Tomy Jul 24 '14 at 6:15
  • @programmer_rkt Tried, it is not working. – Anshu Mishra Jul 24 '14 at 6:19
2

Try it with:

$result = $w->select()
    ->reset(Zend_Db_Select::COLUMNS)
    ->columns('t_text')
    ->from($table)
    ->where('t_store in(0,?)', Mage::app()->getStore()->getStoreId());
  • Sorry, it is not working. – Anshu Mishra Jul 24 '14 at 6:37
  • @AnshuMishra. I've edited the answer. Give it a try now. – Marius Jul 24 '14 at 6:39
  • Still not working. – Anshu Mishra Jul 24 '14 at 6:42
1

Below code worked for me.

$result = $w->select()
    ->from($table, 't_text')
    ->where('t_store in(0,?)', Mage::app()->getStore()->getStoreId());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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