![]() |
connecting and retrieving database data - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: connecting and retrieving database data (/showthread.php?tid=32898) |
connecting and retrieving database data - El Forum - 08-09-2010 [eluser]Unknown[/eluser] hey everyone.i still can't get through in connecting and retrieving data from my database. 1)in my database.php config file,i configured the db_name to my own name,username set to root and active_group allowed as default (for now). 2)in the welcome.php controller file i loaded the db with: $this->load->database('default'); 3)finally in my view page where i wish to display the db data,i typed: <?php $query =$this->db->query("YOUR QUERY"); if($query->num_rows()>0) foreach ($query->result() as $row){ echo $row->title; echo $row->date; echo $row->author; echo $row->content; } Testing it i recieved the following error: FATAL ERROR: Call to a member function on a non-object in c:\program files\easyphp1-8\www\codeigniter_1.7.2\system\application\views\content.php on line 161 Please i will be very greatful if someone can help me figure out my error.Thanks for the assistance given me so far. connecting and retrieving database data - El Forum - 08-09-2010 [eluser]verynewtothis[/eluser] Try changing your 'load database' call to Code: $this->load->database(); connecting and retrieving database data - El Forum - 08-09-2010 [eluser]iConTM[/eluser] If I can add some comments about good practice? ![]() I would follow the MVC pattern: model Code: function get () controller Code: $this->load->database(); view Code: foreach ($rows as $row) Did it work out with the $this->load->database()? greetings connecting and retrieving database data - El Forum - 08-09-2010 [eluser]Juan Velandia[/eluser] Please check this thread, It uses mvc structure. The tables names are different but it's easy (I think) to figure it out http://ellislab.com/forums/viewthread/149458/ hope it helps |