现在我很难将我所有的值放在一个关联数组中。因为我只能从查询中获取最后一个值。不是所有的值。我无法发现错误。这是我的代码:
$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
那是我的问题,我希望你能帮助我。谢谢。