[eluser]ravindral[/eluser]
I am new to CI. Developing first site. I have header that is common for home page and inner page. Now in header i want to display some records from database. They are visible on home page but not in inner page.
In
welcome controller i have written
//////////////////////////////////
function index()
{
$data = array('title' => 'My first CI site');
$this->load->model('subject_model');
$subject_Result=$this->subject_model->subjects();
if($subject_Result->num_rows()>0)
{
$data['subject_result']=$subject_Result->result();
}
$this->parser->parse('header',$data);
$this->parser->parse('home',$data);
$this->parser->parse('footer',$data);
}
//////////////////////////////////
On home page, it is showing list of subjects fetched in subject_model->subjects() function. But in inner page i am getting error :
/////////////
Error:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: subject_result
Filename: views/header.php
Line Number: 42
///////////////
Is that i need to copy below code in each page controller?
$this->load->model('subject_model');
$subject_Result=$this->subject_model->subjects();
if($subject_Result->num_rows()>0)
{
$data['subject_result']=$subject_Result->result();
}
Please help otherwise i will code in wrong way. Help me.
Thanks in anticipation,
Ravindra.