Welcome Guest, Not a member yet? Register   Sign In
To those array experts
#1

I can see the values in the array, but i cant get access to them - Help!!

I am writing the following code in codeigniter

Code:
if ($this->form_validation->run() == FALSE) {
// Bill Not Created
}else {
for($i = 0; $i < $totalElements; $i++) {
$job_date = $job_dates[$i];
$cust = $customer_ids[$i];

$items = new Customer();
$items->where('id', $cust)->where_in('user_id',$uid)->get();
$customer_id_count = array_count_values($customer_ids);
$dates = new Bill_item();
$dates->where('customer_id =',$cust)->where('user_id =',$uid)->where('item_date =', $job_date)->get();
//SELECT * FROM (`bill_items`) WHERE `customer_id` = '6' AND `bill_items`.`user_id` = 2 AND `bill_items`.`item_date` = '2015-08-05'

$data['item_count_item'] = $items->result_count();  
$data['items'] = $items;  
$data['dates2'] = array();
$data['dates'] = array();
$data['total'] = array();
$data['total_for_cost'] = array();
$total1 = 0;
foreach($dates AS $date)
{
$data['dates'][$date->id] = array('cust' => $date->customer_id, 'item_date' => $date->item_date, 'item_hours' => $date->hours, 'item_amount' => $date->amount, 'cost' => ($date->amount*$date->hours), 'total_cost' => ($date->amount*$date->hours), 'cluster_tasks' => array());
$data['total'][$date->id] = array('total_cost' => ($date->amount*$date->hours));  
$new_date=$date->customer_id;
foreach($items AS $item)
{
for($count = 0; $count < $customer_id_count[$item->id]; $count++)
{
$item->id;  
if($item->id==$new_date)
{
$data['dates'][$date->id]['customers'] = array(
'name' => $item->support_item
);
}
}
}
}
$data['dates2'][$i]=$data['dates'];
}  
echo $i; //2015-08-05 6 0 2015-08-07 8 1
$data['dates2'][$i]=$data['dates'];
print_r($data['dates2'][$i]);
$data['total_for_cost'] = array_reduce($data['total'], create_function('$total, $next', '$total += $next["total_cost"]; return $total;'));
}

The above print_r outputs =
0Array ( [23] => Array ( [cust] => 6 [item_date] => 2015-08-05 [item_hours] => 2.00 [item_amount] => 37.00 [cost] => 74 [total_cost] => 74 [cluster_tasks] => Array ( ) [jobs] => Array ( [name] => 3 Aireys Street ) ) )
1Array ( [26] => Array ( [cust] => 8 [item_date] => 2015-08-07 [item_hours] => 1.00 [item_amount] => 40.00 [cost] => 40 [total_cost] => 40 [cluster_tasks] => Array ( ) [jobs] => Array ( [name] => 48 Taroona Road ) ) )



but my form page is only displaying the final record of '7 August 2015 48 Taroona Road 1 hour/s $40/hr $40'

This is doing my head in, I would really appreciate it if anyone ccould point out how to get both records to display. I assume it's because I'm overwriting it somewhere?

Thanks heaps
Reply


Messages In This Thread
To those array experts - by scoobie - 08-22-2015, 11:47 PM
RE: To those array experts - by jLinux - 08-23-2015, 12:21 AM
RE: To those array experts - by scoobie - 08-23-2015, 06:01 AM
RE: To those array experts - by pdthinh - 08-23-2015, 10:02 AM
RE: To those array experts - by scoobie - 08-23-2015, 04:20 PM
RE: To those array experts - by RobertSF - 08-23-2015, 07:26 PM
RE: To those array experts - by scoobie - 08-24-2015, 02:03 AM
RE: To those array experts - by RobertSF - 08-24-2015, 10:57 AM
RE: To those array experts - by mwhitney - 08-24-2015, 02:18 PM
RE: To those array experts - by scoobie - 08-26-2015, 03:46 PM
RE: To those array experts - by scoobie - 08-26-2015, 11:17 PM
RE: To those array experts - by RobertSF - 08-27-2015, 09:00 AM
RE: To those array experts - by mwhitney - 08-27-2015, 01:10 PM



Theme © iAndrew 2016 - Forum software by © MyBB