Reputation: 643
I'm developing a web application in codeigniter. I've a view which lists all complaints in a table. I'm passing an array of complaints from controller to the view. My array from controller looks like this:
Array ( [0] => Array ( [com_id] => 71 [engine_model] => 2 [assigned_to] => Sreejith KM )
[1] => Array ( [com_id] => 70 [engine_model] => KSERIES [assigned_to] => shaun )
[2] => Array ( [com_id] => 68 [engine_model] => fhg [assigned_to] => Din )
[3] => Array ( [com_id] => 69 [engine_model] => HA294 [assigned_to] => Don )
[4] => Array ( [com_id] => 64 [engine_model] => gshsh [assigned_to] => Don,Shaun ) )
I tried to display this array in view using foreach loop. But its not working. Corresponding rows are created but the data is not displayed in td.ie, blank rows are created. Can anyone suggest me a solution for this. Thanks in advance Here's my code:
Contoller:
function re_assigncomplaint()
{
$data['returntech'] = $this->complaint_model->getTechnicians();
$data['returnitems']= $this->complaint_model->getallComplaints_reasign_test();
$data['page_title'] = $this->lang->line("reassign_complaints");
$this->load->view('commons/header', $meta);
$this->load->view('reasign', $data);
$this->load->view('commons/footer');
}
View:
<table id="slData" class="table table-bordered table-hover table-striped table-condensed" style="margin-bottom: 5px;">
<thead>
<tr>
<th></th>
<th><?php echo $this->lang->line("complaint_id"); ?></th>
<th><?php echo $this->lang->line("engine_model"); ?></th>
<th><?php echo $this->lang->line("assigned_to"); ?></th>
</tr>
</thead>
<tbody>
<?php
$i=0;
if(!empty($returnitems))
{
foreach ($returnitems as $return) {
?>
<tr>
<td style="text-align:center;"><input type="checkbox" value="<?php echo $return[$i]['com_id'];?>" name="idcheckbox[]" id="idcheckbox"></td>
<td style="text-align:center;"><?php echo $return[$i]['com_id'];?></td>
<td style="text-align:center;"><?php echo $return[$i]['engine_model'];?></td>
<td style="text-align:center;"><?php echo $return[$i]['assigned_to'];?></td>
</tr>
<?php
$i++;
}
}
?>
</tbody>
</table>
Model:
public function getallComplaints_reasign_test()
{
$myQuery = "select * from app_complaint where assigned_to != 'not assigned'";
$q1 = $this->db->query($myQuery);
if($q1->num_rows() > 0)
{
foreach (($q1->result()) as $row1)
{
$compid=$row1->com_id;
$engine=$row1->engine_model;
$tch = $row1->assigned_to;
$tch1=explode(',',$tch);
$tch2=array();
foreach($tch1 as $types)
{
$techname="select technician_name from technicians where id='$types'";
$q2 = $this->db->query($techname);
if($q2->num_rows() > 0)
{
$row2 = $q2->row();
$tch2[]= $row2->technician_name;
}
}
$tech=implode(',',$tch2);
$cmpl[]=array('com_id'=>$compid,'name'=>$cust,'com_type'=>$comptype,'engine_model'=>$engine,'assigned_to'=>$tech);
}
}
return $cmpl;
}
Upvotes: 1
Views: 1067
Reputation: 10717
You used foreach
loop and $i
var together. You doesnt need $i
. Use as $return['com_type']
instead of $return[$i]['com_type']
foreach ($returnitems as $return)
{
$return['com_type'];
}
Or use foor
loop like following:
for($i = 0; $i < count($returnitems); $i++)
{
$returnitems[$i]['com_type'];
}
Upvotes: 1