Welcome Guest, Not a member yet? Register   Sign In
connecting and retrieving database data

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:

$query =$this->db->query("YOUR QUERY");
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.

Try changing your 'load database' call to

If I can add some comments about good practice? Wink

I would follow the MVC pattern:


function get ()
  $query = $this->db->get('mytable');
  return $query->result();



$rows = $this->my_model->get();

// do some conversion here (if needed)
$data['rows'] = $rows

$this->load->view('content', $data);


foreach ($rows as $row)
echo $row->id;

Did it work out with the $this->load->database()?


[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


hope it helps

Theme © iAndrew 2016 - Forum software by © MyBB