Welcome Guest, Not a member yet? Register   Sign In
Loading database content problem
#1

[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;
#2

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

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

[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()
#5

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




Theme © iAndrew 2016 - Forum software by © MyBB