i am new with codeigniter.I have written controller,model.view.
I want to execute the another query in the model which having the “ID” from first model query in the where condition and pass the seperate results for both the both query in same view.
i have explain it in model and view.
how can i do this.need some syntax how can i do this.
or is this correct way or do somwthing??
Controller
class demo extends CI_Controller
{
function getRecords()
{
$offset = trim($this->input->get('off'));
$this->load->model('demo_model');
$data = $this->demo_model->get_messages($offset);
$return = $this->load->view('demo_view',array('records'=>$data),true);
die($return);
}
}
Model
class demo_model extends CI_Model
{
function get_messages($offset = 0)
{
$q = $this->db->query(" select Id,cloum2 from table");
// want to use ID from above query in to second query
// Like sql="select * from table where id='$id'" ;
// and how i pass the separate result for both query inthe view
return $q->result_array();
}
}
View demo_view;
<?php foreach($records as $row) :?>
<div> do something with $row </div>
<div> //want use second query foreach here </div>
<?php endforeach ;?>
Both queries will return PHP arrays so you can do something like.
MODEL
CONTROLLER
VIEW
(But this isn’t such a good idea as you will run a bunch of queries to the model. Its better to think of a nicer query)