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

So it's almost working. I used
Code:
for($i = 0; $i < $totalElements; $i++) {
$job_date = $job_dates[$i]; //2015-08-05 6 2015-08-07 8
$cust = $customer_ids[$i];

$items = new Customer();
$items->where('id', $cust)->where_in('user_id',$uid)->get();
//SELECT * FROM (`customers`) WHERE `idrr` = '6' AND `customers`.`user_id` IN (2)
$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_idmm` = '6' AND `bill_items`.`user_id` = 2 AND `bill_items`.`item_date` = '2015-08-05'
$data['item_count_item'] = $items->result_count();  //1
$data['items'] = $items;  
//$data['dates3'] = array();
$data['dates2'] = array();
$data['dates'] = array();
$data['total'] = array();
$data['total_cost'] = array();
$data['total_for_cost'] = array();
foreach($dates AS $date)
{
 $data['dates'][$i][$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]['jobs'] = array(
'name' => $item->support_item
);
}
}
}
}  
$data['dates2'][$i]=$data['dates'];  
$data['dates3'][$i]=$data['dates2'][$i];  
$data['total_for_cost'] = array_reduce($data['total'], create_function('$total, $next', '$total += $next["total_cost"]; return $total;'));
}
for($i = 0; $i < $totalElements; $i++) {
echo $i;
print_r($data['dates3'][$i]);
echo "<br>";
}
}

this output

0Array ( [0] => Array ( [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 ( ) ) ) [23] => Array ( [jobs] => Array ( [name] => 3 Aireys Street Aireys Inlet ) ) )
1Array ( [1] => Array ( [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 ( ) ) ) [26] => Array ( [jobs] => Array ( [name] => 48 Taroona Road ) ) )

looking good, but then i did a var_dump on the view and i got

array(2) { [0]=> array(2) { [0]=> array(1) {
[23]=> array(7) { ["cust"]=> string(1) "6" ["item_date"]=> string(10) "2015-08-05" ["item_hours"]=> string(4) "2.00" ["item_amount"]=> string(5) "37.00" ["cost"]=> float(74) ["total_cost"]=> float(74) ["cluster_tasks"]=> array(0) { } } } [23]=> array(1) { ["jobs"]=> array(1) { ["name"]=> string(28) "3 Aireys Street Aireys Inlet" } } } [1]=> array(2) { [1]=> array(1) {
[26]=> array(7) { ["cust"]=> string(1) "8" ["item_date"]=> string(10) "2015-08-07" ["item_hours"]=> string(4) "1.00" ["item_amount"]=> string(5) "40.00" ["cost"]=> float(40) ["total_cost"]=> float(40) ["cluster_tasks"]=> array(0) { } } } [26]=> array(1) { ["jobs"]=> array(1) { ["name"]=> string(16) "48 Taroona Road " } } } }

not good as the view couldnt see the elements in the array

so all i need now is to know how to remove the top empty levels in the array??

so to go from

array(2) {
[0]=> array(2) { [0]=> array(1) { [23]=> array(7) { ["cust"]=> string(1) "6" ["item_date"]=> string(10) "2015-08-05" ["item_hours"]=> string(4) "2.00" ["item_amount"]=> string(5) "37.00" ["cost"]=> float(74) ["total_cost"]=> float(74) ["cluster_tasks"]=> array(0) { } } } [23]=> array(1) { ["jobs"]=> array(1) { ["name"]=> string(28) "3 Aireys Street Aireys Inlet" } } }
[1]=> array(2) { [1]=> array(1) { [26]=> array(7) { ["cust"]=> string(1) "8" ["item_date"]=> string(10) "2015-08-07" ["item_hours"]=> string(4) "1.00" ["item_amount"]=> string(5) "40.00" ["cost"]=> float(40) ["total_cost"]=> float(40) ["cluster_tasks"]=> array(0) { } } } [26]=> array(1) { ["jobs"]=> array(1) { ["name"]=> string(16) "48 Taroona Road " } } } }


to

array(2) {
[23]=> array(7) { ["cust"]=> string(1) "6" ["item_date"]=> string(10) "2015-08-05" ["item_hours"]=> string(4) "2.00" ["item_amount"]=> string(5) "37.00" ["cost"]=> float(74) ["total_cost"]=> float(74) ["cluster_tasks"]=> array(0) { } } } [23]=> array(1) { ["jobs"]=> array(1) { ["name"]=> string(28) "3 Aireys Street Aireys Inlet" } } }
[26]=> array(7) { ["cust"]=> string(1) "8" ["item_date"]=> string(10) "2015-08-07" ["item_hours"]=> string(4) "1.00" ["item_amount"]=> string(5) "40.00" ["cost"]=> float(40) ["total_cost"]=> float(40) ["cluster_tasks"]=> array(0) { } } } [26]=> array(1) { ["jobs"]=> array(1) { ["name"]=> string(16) "48 Taroona Road " } } } }

note the '[0]=> array(2) { [0]=> array(1)' at start

and then I think it'll work fine

I've ttried lots already like 'array_shift' 'array_merge' and a couple of others i found on google and didn't do anything. Please, if there any suggestions I'd be eternally grateful.

PS I will investigate the debugging options soon and i appreciate your help so far

Thanks
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