在数组中使用while循环

时间:2014-12-22 19:48:39

标签: php mysql arrays mysqli

尝试通过将mysql查询中的值放入数组然后计算持续时间来生成最大和最小持续时间。

我不知道如何在数组中运行查询。请帮忙。

这是我的确切代码:

$mindur_query = mysql_query("SELECT *, CONCAT(`cancel_date`, `pur_date`) AS orderdate FROM `sales_report` WHERE $cancelled_query $req_query $req_status CONCAT(`cancel_date`, `pur_date`) BETWEEN '$req_date1' AND '$req_date2' ORDER BY orderdate"); 
while($mindur_fetch = mysql_fetch_array($mindur_query)){
$mindurtermi_date = $mindur_fetch['termi_date'];
$mindurstr_date = $mindur_fetch['str_date'];

$diff = (strtotime($mindurtermi_date)- strtotime($mindurstr_date))/24/3600; 
$total_diff = number_format($diff, 0); // Want to put this value in array
}

我想要这样的数组: $ array = array($ total_diff); // $ total_diff的所有值

1 个答案:

答案 0 :(得分:1)

这样做:

$total_diff[] = number_format($diff, 0);