[eluser]Zack Kitzmiller[/eluser]
Updated your code to work. It's not pretty, but it get's the job done. You can't return twice in one function. 'return' exits the function.
You were returning the 'result' object from the model, not the query object. and you can't run 'num_rows()' on the result object.
I just return the object if there are rows in the model, and check to see if it's null/notnull in the view.
[quote author="bcarter" date="1272925080"]Hi there
Real noob question here. I'm trying to display a sub menu if num_rows > 0 but it's not working. When I view the page it says...
Quote:Fatal error: Call to a member function num_rows() on a non-object
Here's the code...
Model
Code:
class Subnav_model extends Model {
function Subnav_model() {
parent::Model();
}
function subnav($id){
$query2 = $this->db->get_where('sub_content', array('section' => $id));
if ($query2->num_rows() > 0) {
return $query2->result();
} else {
return false;
}
}
}
View
Code:
<?php if (!empty($query2)) { ?>
<h2>Content Area</h2>
<ul>
<?php foreach($query2 as $row) {?>
<li><a >uri->segment(1) ?>/information/<?php echo $row->sub_content_ID ?>"><?php echo $row->sub_content_title ?></a></li>
<?php } ?>
</ul>
<?php } //end of if num_rows ?>
Controller
Code:
class Home extends Controller {
function Home()
{
parent::Controller();
}
function index() {
$id = '1';
$data['page_title'] = "Welcome to Rebus Training Ltd";
$this->load->model('Nav_model');
$data['query'] = $this->Nav_model->nav();
//$this->load->view('head', $data);
$this->load->model('Subnav_model');
$data['query2'] = $this->Subnav_model->subnav($id);
$this->load->view('head', $data);
$this->load->view('home_view', $data);
}
}
Can anyone help? I know it's a massively basic question!!!
Thanks a lot![/quote]