Wednesday, 28 August 2013

Error in getting all the array values using associative array method

Error in getting all the array values using associative array method

now i am having a hard time in placing all my values in an associative
array. Because I can only get the last value from query. Not all the
values. I can't spot the error. Here's my code:
$sqlGetSerializedValues = "SELECT cscart_order_data.order_id AS order_id,
cscart_orders.total AS total, cscart_order_data.data AS data_serialize,
cscart_orders.timestamp AS date, cscart_orders.status AS status FROM
cscart_orders
LEFT JOIN cscart_order_data
ON cscart_orders.order_id =
cscart_order_data.order_id
WHERE cscart_order_data.type = 'I'
AND cscart_orders.timestamp BETWEEN
UNIX_TIMESTAMP('2011-01-01 00:00:00')
AND UNIX_TIMESTAMP('2013-01-31
23:59:59') limit 10
";
$resultGetSerialize = $this->db->query($sqlGetSerializedValues);
echo "<pre>";
$var_data = array();
foreach($resultGetSerialize->result_array() as $row1){
$var_data[] = array(
'id' => $row1['order_id'],
'total' => $row1['total'],
'status' => $row1['status'],
'data' => unserialize($row1['data_serialize']),
'date' => $row1['date']
);
}
$range = array();
foreach($var_data as $data){
$id = $data['id'];
$total = $data['total'];
$cost = $data['data']['cost'];
$var_date = $data['date'];
$status => $data['status'];
$date_var = date('Y-m-d H:i:s',$var_date);
$grand_total = $total + $cost;
$cost_ratio = ($cost/$grand_total) * 100;
$paid_ratio = ($total/$grand_total) * 100;
$range[] = $cost_ratio;
$test = array(
'id' => $data['id'],
'ratio' => $cost_ratio,
'status' => $status
);
}
echo "</table>";
print_r($test); //this will return the last index from my array
That;s my problem guys i hope you can help me. Thanks.

No comments:

Post a Comment