当前位置:Gxlcms > PHP教程 > 页面执行时间太长,请各位大大帮忙看看

页面执行时间太长,请各位大大帮忙看看

时间:2021-07-01 10:21:17 帮助过:13人阅读

订单统计                StartTime = $this->get_microtime();    }     function stop()    {        $this->StopTime = $this->get_microtime();    }     function spent()    {        return round(($this->StopTime - $this->StartTime) * 1000, 1);    } }$runtime= new runtime;$runtime->start();include("conn.php");$to_date=date('Y-m-d');//按包装区域来统计邮件总数function sale_address_package_statistics($date,$account,$package){$sql="select `number` from `sale_orders` where `account`='$account' and date(`upload_date`) ='$date' GROUP BY `number`";$Result = mysql_query($sql);$number="(`number`='' ";while($rs = mysql_fetch_array($Result)){$number.=" or `number`=".$rs[0];}$number.=")";$sql_order_address="SELECT * FROM `sale_orders` T ";$sql_order_address.="WHERE ".$number;$sql_order_address.="AND `account` ='$account' ";if($package=='MIX'){$sql_order_address.="AND 1<(select count(*) from `sale_orders` where ".$number." AND `account` ='$account' AND `recipient_name`=T.`recipient_name`  AND `ship_address_1`=T.`ship_address_1`) ";}else{$sql_order_address.="AND 1=(select count(*) from `sale_orders` where ".$number." AND `account` ='$account' AND `recipient_name`=T.`recipient_name`  AND `ship_address_1`=T.`ship_address_1`) ";$sql_order_address.="AND `package_area`='$package' ";}$sql_order_address.="GROUP BY `recipient_name` , `ship_address_1`";$result_label = mysql_query($sql_order_address);$order_address=mysql_affected_rows();if(empty($order_address)){return 0;}else{return $order_address;}}?>

订单统计

PM_AC CO_AC UK_AC UK_FR UK_DE
SZ HK MIX SZ HK MIX SZ HK MIX SZ HK MIX SZ HK MIX
stop(); $runtimea= new runtime;$runtimea->start(); ?>

stop();echo "邮件统计页面执行时间: ".$runtime->spent()." 毫秒,订单统计页面执行时间:".$runtimea->spent()." 毫秒"; ?>


这个页执行要75秒左右,这还只是显示一天的数据,实际上我需要显示一个月的数据


主要是那个查询语句的问题,以下语句如果查询的记录在1700条左右的时候,需要35秒
SELECT * FROM `sale_orders` T
WHERE (`number`='' or `number`=81)
AND 1=(select count(*) from `sale_orders`
where (`number`='' or `number`=81)
AND `recipient_name`=T.`recipient_name`
AND `ship_address_1`=T.`ship_address_1`)
AND `package_area`='SZ'
GROUP BY `recipient_name` , `ship_address_1`


请问怎么优化啊?显示一天的数据需要75秒,那一个月的数据不是等吃一餐饭还没显示完


回复讨论(解决方案)

具体情况需具体分析,毕竟不是在做文字游戏
调试查询指令应听从 EXPLAIN 的建议

尽量少用select * ,需要哪个字段查哪个,还有,加索引

数据表需要优化。
可否desc给大家看看呢

人气教程排行