我已经使用照片mysql完成了我的代码,但我执行了7个多小时,请指导我减少时间 [英] I have done my code using photo mysql but I take more than 7 hours in execution please guide me for reduce time
本文介绍了我已经使用照片mysql完成了我的代码,但我执行了7个多小时,请指导我减少时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ini_set('max_execution_time', 15000);
ini_set("memory_limit","1028M");
mysql_query('TRUNCATE TABLE scrip_average');
$sql_all = mysql_query("select * From all_scrip limit 8000");
while($row_all = mysql_fetch_array($sql_all))
{
$SC_CODE=$row_all['SC_CODE'];
$sql_last = mysql_query("select * From scrip where SC_CODE='$SC_CODE' ORDER BY ID DESC LIMIT 1");
while($row_last = mysql_fetch_array($sql_last))
{
$LAST_OPEN=$row_last['OPEN'];
$LAST_HIGH=$row_last['HIGH'];
$LAST_CLOSE=$row_last['CLOSE'];
$LAST_LOW=$row_last['LOW'];
}
for ($n = 200; $n >0; $n--)
{
$total_OPEN=0;
$total_HIGH=0;
$total_LOW=0;
$total_CLOSE=0;
$result_open=mysql_query("SELECT SUM(OPEN) AS total_value FROM scrip where SC_CODE='$SC_CODE' ORDER BY ID DESC LIMIT $n");
$total_OPEN=mysql_result($result_open,0,0);
$result_high=mysql_query("SELECT SUM(HIGH) AS total_value FROM scrip where SC_CODE='$SC_CODE' ORDER BY ID DESC LIMIT $n");
$total_HIGH=mysql_result($result_high,0,0);
$result_low=mysql_query("SELECT SUM(LOW) AS total_value FROM scrip where SC_CODE='$SC_CODE' ORDER BY ID DESC LIMIT $n");
$total_LOW=mysql_result($result_low,0,0);
$result_close=mysql_query("SELECT SUM(CLOSE) AS total_value FROM scrip where SC_CODE='$SC_CODE' ORDER BY ID DESC LIMIT $n");
$total_CLOSE=mysql_result($result_close,0,0);
$total_OPEN=$total_OPEN/$n;
$total_HIGH=$total_HIGH/$n;
$total_LOW=$total_LOW/$n;
$total_CLOSE=$total_CLOSE/$n;
$LOW_status='negetive';
if($total_LOW>$LAST_LOW)
{
$LOW_status='possitive';
}
$HIGH_status='negetive';
if($total_HIGH>$LAST_HIGH)
{
$HIGH_status='possitive';
}
$OPEN_status='negetive';
if($total_OPEN>$LAST_OPEN)
{
$OPEN_status='possitive';
}
$CLOSE_status='negetive';
if($total_CLOSE>$LAST_CLOSE)
{
$CLOSE_status='possitive';
}
$data=array(
'date'=>$n,
'SC_CODE'=>$SC_CODE,
'OPEN'=>$total_OPEN,
'HIGH'=>$total_HIGH,
'LOW'=>$total_LOW,
'CLOSE'=>$total_CLOSE,
'LOW_status'=>$LOW_status,
'HIGH_status'=>$HIGH_status,
'OPEN_status'=>$OPEN_status,
'CLOSE_status'=>$CLOSE_status);
//'img_postdate' =>date("y,m,d"),
$query=insert("scrip_average",$data);
}
}
我是什么尝试过:
执行需要太多时间请帮我减少执行时间
What I have tried:
It takes too much time in execution please help me to reduce execution time
推荐答案
sql_all = mysql_query( select * from all_scrip limit 8000);
while(
sql_all = mysql_query("select * From all_scrip limit 8000"); while(
row_all = mysql_fetch_array(
row_all = mysql_fetch_array(
sql_all))
{
sql_all)) {
这篇关于我已经使用照片mysql完成了我的代码,但我执行了7个多小时,请指导我减少时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文