I have a question about CodeIgniter and how to get some information from some tables using a controller and then have it displayed in a view
I have it working using 6 tables, but I've changed the layout of the database and the names of the tables and I can't quite work out how to change the code (i'm no longer using some of the tables that i was using so theoretically it should be easier!) to have it working again and I'm hoping it will be an easy 'find' for someone to look at and give me some pointers.
It has a couple of errors of
Message: Undefined variable: cluster_task
And then one for the date of
Message: Undefined index:item_date
Complaining about the view, but there’s probably the way I’ve defined in the controller, and I have tried changing it about 100 times and I cant see where the error(s) are?
This is what it comes out with in browser
From 3 June 2015 to 5 June 2015
Date Support Item Ref Number Hours Price Cost
4 June 2015
3 June 2015
5 June 2015
5 June 2015
1 January 1970
The controller code is – there’s more but this should be the relevant part =
Code:
$items = new Cluster_task();
$items->where_in('id', $cluster_task_ids)->order_by('id', 'asc')->get();
$cluster_task_id_count = array_count_values($cluster_task_ids);
$dates = new List_item();
$dates->where_in('user_list_id', $id)->where('item_date >=', $start)->where('item_date <=', $end)->order_by('cluster_task_id', 'asc')->get();
if($items->exists()) {
echo $data['item_count_item'] = $items->result_count();
$data['items'] = $items;
$data['dates'] = array();
foreach($dates AS $date)
{
$data['dates'][$date->id] = array('item_date' => $date->item_date, 'cluster_tasks' => array());
}
foreach($items AS $item)
{
for($count = 0; $count < $cluster_task_id_count[$item->id]; $count++)
{
$data['dates'][$item->cluster_task_id]['cluster_tasks'][$item->cluster_task_id] = array(
'name' => $item->cluster_task_support_item
);
}
}
}
$data['start'] = $start;
$data['end'] = $end;
$this->cfd->build('diet/preview_claim', $data);
And the view code is – again, there’s more but this should be the relevant part =
Code:
<table class="atable">
<tr>
<th colspan="12">From <?php echo date('j F Y', strtotime($start)) ?> to <?php echo date('j F Y', strtotime($end)) ?></th>
</tr>
<tr>
<td>Date</td>
<td>Support Item</td>
<td>Ref Number</td>
<td>Hours</td>
<td>Price</td>
<td>Cost</td>
</tr>
<?php
foreach($dates AS $date) {
$date = $date['item_date']; //item_categories - name ie fruit
echo '<td class="special_column1">'.date('j F Y', strtotime($date)).'</td>';
foreach($date['cluster_tasks'] AS $cluster_task)
{
echo '<tr>';
echo '<td class="special_column1">'.date('j F Y', strtotime($date)).'</td>';
echo '<td class="special_column3">'.$cluster_task['name'].'</td>';
echo '</tr>';
$name = '';
}
}
?>
</table>
If i take out
Code:
foreach($items AS $item)
{
for($count = 0; $count < $cluster_task_id_count[$item->id]; $count++)
{
$data['dates'][$item->cluster_task_id]['cluster_tasks'][$item->cluster_task_id] = array(
'name' => $item->cluster_task_support_item
);
}
}
from the controller and the relevant part in view the dates return with no error messages (and not the 1 January 1970 either) but i want it to display the support_item field next to the date. I should be able to work out how to get the other columns once i can see where i'm going wrong with just the one that i'm trying to output.
Thanks for your time.