Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

get the data from the table
 
nkdineshdct
Member
 
Avatar
Total Posts:  66
Joined:  2008-08-29
India
 

Hello All,

I want to get the data from the table in the database.. How can i get the data?

I have created a table called “distributor” and i have fields such as id, name, email.

How i can get the data from the table distributor with the help of the code.

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brandlive_br
Guru
 
Avatar
Total Posts:  653
Joined:  2008-05-19
Buenos Aires, Argentina
 

Maybe you can try with something like this.

$connection Mage::getSingleton('core/resource')->getConnection('distributor_read'); //I assuming that you created the model for your table
$result $connection->fetchAll("SELECT field FROM table WHERE field = condition");

Then, you obtain an array with the result.

I recommend you that use the Magento database abstraction.

 
Magento Community Magento Community
Magento Community
Magento Community
 
nkdineshdct
Member
 
Avatar
Total Posts:  66
Joined:  2008-08-29
India
 

Hello Damian,

Thanks for your kind reply.

As i m new to magento , i dont know about th model for the table.
How i can create model for the table and where?

Your help is highly appreciated.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brandlive_br
Guru
 
Avatar
Total Posts:  653
Joined:  2008-05-19
Buenos Aires, Argentina
 

I haven’t bookmarked the wiki article, but there is one about how to create a custom module.
I made a little collaboration with that wiki (and the tool that you can download).
I suggest that you start there.
The tool create all the stuff that you need for your module. My recomendation is that you start to test and read that articule (if you want to build your own modules, of course).

 
Magento Community Magento Community
Magento Community
Magento Community
 
nkdineshdct
Member
 
Avatar
Total Posts:  66
Joined:  2008-08-29
India
 

When i give the code and while executing , i got the error

Fatal error: Call to a member function fetchAll() on a non-object

Can u give me a suggestion

 
Magento Community Magento Community
Magento Community
Magento Community
 
nkdineshdct
Member
 
Avatar
Total Posts:  66
Joined:  2008-08-29
India
 

yes i have created the custom module using the module creator.

but i added the separate table and i want to get the data from that table into my custom module.

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brandlive_br
Guru
 
Avatar
Total Posts:  653
Joined:  2008-05-19
Buenos Aires, Argentina
 

I’m thinking that I post an example from early versions (when I made some custom funcitonalities).... I need to test besfore re-post the example.

 
Magento Community Magento Community
Magento Community
Magento Community
 
nkdineshdct
Member
 
Avatar
Total Posts:  66
Joined:  2008-08-29
India
 

Ok thanks Damian

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top