I have this code where data is being defined as far as I can see, these are the errors I am getting:
PHP Error was encountered
Severity: Notice
Message: Undefined variable: empdata
Filename: views/employee.php
Line Number: 51**
Backtrace:
File: C:\xampp\htdocs\providentfund\application\views\employee.php Line: 51 Function: _error_handler
File: C:\xampp\htdocs\providentfund\application\libraries\BaseController.php Line: 99 Function: view
File: C:\xampp\htdocs\providentfund\application\controllers\Employee.php Line: 19 Function: loadViews
File: C:\xampp\htdocs\providentfund\index.php Line: 315 Function: require_once
controller:
public function display_all()
{
$result=$this->Employee_model->display_all();
$data['empdata']=$result;
$this->loadViews("employee", $this->global, NULL);
}
model:
function display_all()
{
$query=$this->db->query("select * from employetbl");
return $query->result();
}
and the view:
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>Rendering engine</th>
<th>Browser</th>
<th>Platform(s)</th>
<th>Engine version</th>
<th>CSS grade</th>
</tr>
</thead>
<tbody>
<?php
$cnt=1;
foreach($empdata as $rec)
{
print_r($empdata);
die();
?>
<tr>
<td><?php echo $rec['fullName'];?></td>
</tr>
<?php
// for serial number increment
$cnt++;
} ?>
Why do I get Error Message "undefined variable"?
$this->load->view('employee', $data);
– frogman578