CodeIgniter Forums
Loading database content problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Loading database content problem (/thread-43922.html)



Loading database content problem - El Forum - 07-27-2011

[eluser]BenSeagrave[/eluser]
I'm trying to implement a blog like feature to my website. I have inserted dummy data into my database and set up the config files in codeigniter. If you go to http://pheonixstudios.co.uk/site you can see the error that I am getting.

This is my controller :

Code:
<?php

class Site extends CI_Controller
{
    public function index()
    {
        $data = array(
            'pageTitle' => 'Home',
            'main_content' => 'home_view',
            'bannerText' => 'Pheonix Studios'
        );
        
        if($query = $this->site_model->getRecords())
        {
            $data['records'] = $query->result();
        }
                
        $this->load->view('includes/template', $data);
    }
}

?>


and this is the part of the home_view.php file you will need to see:

Code:
<div id="primary" class="grid_15">
      &lt;?php foreach($query->result() as $row): ?&gt;
    <article>
      <h3>&lt;?=$row->title?&gt;</h3>
      <strong><p class="articleDate">Posted on &lt;?=$row->date_created?&gt;</p></strong>
      <p>&lt;?=$row->body?&gt;</p>
    </article>
      &lt;?php endforeach; ?&gt;
  </div>


This is also the model:

Code:
&lt;?php

class Site_Model extends CI_Model
{
    function index()
    {
        
    }
    
    function getRecords()
    {
        $query = $this->db->get('blogEntries');
        return $query->result();
    }

}

?&gt;



Loading database content problem - El Forum - 07-27-2011

[eluser]Wondering Coder[/eluser]
your using result() 3x. Remove your result() in the controller and model.


Loading database content problem - El Forum - 07-27-2011

[eluser]BenSeagrave[/eluser]
But surely I need to keep the result function in the files to set it with the results from the db?


Loading database content problem - El Forum - 07-27-2011

[eluser]jmadsen[/eluser]
for example:

Code:
if($query = $this->site_model->getRecords())
        {
            $data['records'] = $query->result();
        }

in your getRecords() function, you are returning $query->result().

so, $query = $function_query->result()

then you are taking $query->result() again.

so, you are really calling $query->result()->result()


Loading database content problem - El Forum - 07-27-2011

[eluser]BenSeagrave[/eluser]
So can you show me what I will need to do? Like edit my code and paste it back Tongue