connecting and retrieving database data |
[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.
[eluser]verynewtothis[/eluser]
Try changing your 'load database' call to Code: $this->load->database();
[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
[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 |
Welcome Guest, Not a member yet? Register Sign In |