Welcome Guest, Not a member yet? Register   Sign In
n00b question - query error, help please!
#1

[eluser]Rick Blackdog[/eluser]
Hey folks, I'm rather embarrassed to be asking this and I'm sure the answer is straightforward. I'm just new to frameworks and have settled on codeigniter as my weapon of choice.

Just following the creat a blog in 20 mins guide and trying to replicate some of it...

Here's the error I see when I call the listing_view.php page:

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined variable: query

Filename: views/listing_view.php

Line Number: 3


Fatal error: Call to a member function result() on a non-object in /Applications/MAMP/htdocs/weknowagood/test/system/application/views/listing_view.php on line 3

and here's the code from that file:

Code:
<ul>&lt;?php foreach($query->result() as $row): ?&gt;
    <li>&lt;?=$row->company?&gt;</li>
&lt;?php endforeach; ?&gt;</ul>

Can't see where I'm going wrong but I suspect it's a configuration problem. I've removed index.php with .htaccess (that's working ok).

Any ideas - thanks for the help! :red:

Rick
#2

[eluser]sketchynix[/eluser]
Post your controller function that generates the view. It looks like the variable $query is not getting passed into the view.
#3

[eluser]Rick Blackdog[/eluser]
Here it is, many thanks...

&lt;?php

class Listing extends Controller {

function Listing() {
parent::Controller();

$this->load->helper('url');

// $this->load->scaffolding('profiles');
}

function index() {
$this->load->view('header_view');
$data['query'] = $this->db->get('profiles');
$this->load->view('listing_view');
}
}
#4

[eluser]sketchynix[/eluser]
you need to pass the $data into the view, like so..
Code:
$data[‘query’] = $this->db->get(‘profiles’);
      $this->load->view(‘listing_view’,$data);

let me know if that doesn't work
#5

[eluser]Rick Blackdog[/eluser]
Yeah that worked, thanks!




Theme © iAndrew 2016 - Forum software by © MyBB