i am using codeigniter. i have a table to be displayed in a view file. so i have a model where i fire a query to get the data from table.
function my_active_requests()
{
$user_id = $this->session->userdata('user_id');
$this->db->select('id,request_date,required_by_date');
$this->db->where('requested_by',$user_id);
return $this->db->get('requests');
///also tried with
//$query = $this->db->get('requests');
///$number_of_rows = $query->num_rows;
//return $query;
//return $number_of_rows;
//but no result
}
this is the model function.
this is my controller
function my_active_req()
{
$this->bloodline_model->my_active_requests();
//also tried without this//
$query = $this->db->get('requests');
//and this//
$number_of_rows = $query->num_rows;
$this->load->view('my_active_req');
}
and this is my view
<?php foreach ($query->result() as $row) { ?>
<tr>
<td><?php echo $row->id; ?></td>
<td><?php echo $row->request_date; ?></td>
<td><?php echo $row->required_by_date; } ?></td>
</tr>
</table>
but the error is undefined variable $query.
i think , i am not able to return the $query and other data from my model to controller and controller to my view.
Please provide me with the solution.
`
Change this line:
The second parameter of the
view()loader function allows you to pass variables into the view.However, you’re largely circumventing the purpose of MVC separation. You want the controller to “ask” for information from the model (not just straight from the database; otherwise, what’s the point of a model?), and then “pass” it to the view. The controller knows what the view needs to function.