我有一个PHP脚本,它可以为3个表提取数据,并且做一些数学并不是最好看的但是它的问题是我的问题是它们已经超过35,000次这需要做到现在它只能够在这里50分钟做几百就是代码
<?php
//my sql
ini_set('max_execution_time', 3000);
$servername = "x.x.x.x";
$username = "uaer";
$password = "psass";
$dbname = "evemur";
$avgvar = "10";
//mysql con string
$con = mysqli_connect("127.0.0.1", "root", "", "evemur");
$sql = "SELECT * FROM `industryactivityproducts` WHERE `activityID` = 1 ORDER BY `typeID` ASC ";
$result = mysqli_query($con, $sql) or die(mysqli_error($con));
$reret = mysqli_num_rows($result);
for ($x = 0; $x <= $reret -1; $x++) {
$row = mysqli_fetch_row($result);
$blue = $row[0];
$ter = $row[1];
$fitem = $row[2];
$dqut = $row[3];
$cost = 0;
$sql2 = "SELECT * FROM `industryactivitymaterials` WHERE `typeID` = $blue AND `activityID` = 1 ORDER BY `typeID` ASC ";
$result2 = mysqli_query($con, $sql2) or die(mysqli_error($con));
// retures the mat to make and qut
$reret4 = mysqli_num_rows($result2);
for ($s = 0; $s <= $reret4 -1; $s++) {
$reret2 = mysqli_fetch_row($result2);
$mat = $reret2[2];
$matq = $reret2[3];
for ($f = 0; $f <= 1 -1; $f++) {
$avgprice = 0;
$sql3 = "SELECT * FROM `items` WHERE `Buy` NOT LIKE '1' AND `Volume Entered` >1 AND `Type` = $mat ORDER BY `Price` ASC ";
$result3 = mysqli_query($con, $sql3) or die(mysqli_error($con));
for ($d = 0; $d <= $avgvar; $d++) {
$row3 = mysqli_fetch_row($result3);
$avgprice = $avgprice + $row3[2];
}
$avgprice = $avgprice / ($avgvar + 1);
$cost = $cost + ($avgprice * $matq);
$avgprice = number_format($avgprice, 2, '.', ',');
echo $avgprice . " ".$mat. "<br>";
}
}
$sql5 = "SELECT * FROM `items` WHERE `Buy` NOT LIKE '' AND `Type` = $fitem ORDER BY `items`.`Price` DESC ";
$result5 = mysqli_query($con, $sql5) or die(mysqli_error($con));
$row5 = mysqli_fetch_row($result5);
$pfit = $row5[2] * $dqut;
$pfit1 = $pfit - $cost;
$cost = number_format($cost, 2, '.', ',');
$pfit1 = number_format($pfit1, 2, '.', ',');
echo $fitem." cost:" . $cost ." ". "you make " . $pfit1 ;
}
?>
答案 0 :(得分:1)
在进入循环之前,您应该从表中加载所有数据,而不是在每个循环中执行MYSQL函数。这应该会大大提高脚本的速度。
除此之外,您只是执行基本的数学运算,因此速度方面的改善并不多。