I am fairly new to codeigniter and cant seem to get a hold of this problem, in short i am having problem understanding the flow of data among the CodeIgniter framework. All i want to display is data taken from database using modals and display them in view..
The code in my controller is:
$unitData =$this->ClientUnit->getBlockUnits($client_block_ID);
foreach ($unitData->result() as $row){
for ($i=0; $i < 3; $i++) {
$client_unit_name[$i] = $row->client_unit_name[$i];
$unit_owner_name[$i] = $row->unit_owner_name[$i];
}
}
$data['client_unit_name'] = $client_unit_name;
$data['unit_owner_name'] = $unit_owner_name;
$this->load->view('newblock_unit',$data);
My modal file is:
function getBlockUnits($client_block_ID) {
$query = $this->db->query('SELECT * FROM client_units where client_block_ID="'.$client_block_ID.'"');
return $query;
}
As you can see, from my modal and controller code, the problem is because of multiple rows which are returned, currently i am getting only the last row in all the outputs of view, not individual rows...
I think the problem is that you are not returning an object or array. In the model you should use, for an object:
return $query->result();
Or for an array:
return $query->result_array();
EDIT: You can read everything about this here http://ellislab.com/codeigniter/user-guide/database/results.html
you can send the whole array in view and loop it there
$unitData =$this->ClientUnit->getBlockUnits($client_block_ID);
$data['unitData '] = $unitData->result_array();
$this->load->view('newblock_unit',$data);
in in your view use loop to get the corresponding that
foreach($unitData as $row){
echo row['client_unit_name'];
echo row['unit_owner_name'];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.