有誰知道更有效的方式來編寫以下內容。我的加載時間超過一分鐘。這是我在更長的代碼集之後想出來的。PHP查詢加載速度太慢。如何加快速度?
$max = $i + 25;
while ($i < $max)
{
$memberno = $memberid;
if($pulledid!=$memberid)
{
$pulledid = mysql_result($result99,$i,"id_member");
$sql_statement = "Select vinyl_fortrade.ImageID,vinyl_fortrade.MemberID from vinyl_fortrade where exists (Select ImageID from vinyl_wanted WHERE MemberID = $memberno AND vinyl_wanted.ImageID = vinyl_fortrade.ImageID) AND vinyl_fortrade.MemberID=$pulledid";
$result=mysql_query($sql_statement)or die(mysql_error());
$num=mysql_numrows($result);
if($num>0)
{
$sql_statement2 = "Select vinyl_wanted.ImageID, vinyl_wanted.MemberID from vinyl_wanted where exists (Select ImageID from vinyl_fortrade WHERE MemberID = $memberno AND vinyl_wanted.ImageID = vinyl_fortrade.ImageID) AND vinyl_wanted.MemberID=$pulledid";
$result2=mysql_query($sql_statement2)or die(mysql_error());
$num2=mysql_numrows($result2);
$membername = mysql_result($result99,$i,"smf_members.member_name");
$userid2 = mysql_result($result99,$i,"smf_members.id_member");
if ($num2 > 0)
{
$lastlogged = mysql_result($result99,$i,"smf_members.last_login");
echo '<td><a href="http://vinylmationconnection.com/forum/index.php?action=pm;sa=send; u='.$userid.'"style="color: #FFF">'.$membername.'</a><br>Last Logged In:<br>';
echo date('Y-m-d', $lastlogged);
echo ':</td>';
echo '<td>';
$n = 0;
$m = 0;
while ($n < $num)
{
$title=mysql_result($result,$n,"vinyl_fortrade.ImageID");
$sql_statementj = "Select * from vinyl_figures WHERE ImageID = '$title'";
$resultj=mysql_query($sql_statementj)or die(mysql_error());
$seriess=mysql_result($resultj,0,"vinyl_figures.Series");
echo '<img src="http://vinylmationconnection.com/images/p'.$seriess.'/'.$title.'.jpg">';
$n++;
if($n%4=="0")
echo "<br>";
}
echo '</td><td>';
while ($m < $num2)
{
$title=mysql_result($result2,$m,"vinyl_wanted.ImageID");
$sql_statementj = "Select Series from vinyl_figures WHERE ImageID = '$title'";
$resultj=mysql_query($sql_statementj)or die(mysql_error());
$seriess=mysql_result($resultj,0,"vinyl_figures.Series");
echo '<img src="http://vinylmationconnection.com/images/p'.$seriess.'/'.$title.'.jpg">';
$m++;
if($m%4=="0")
echo "<br>";
}
echo '</td> </tr>';
}
}
}
$i++;
}
請讓我知道如果代碼是自我解釋。
通常,解決性能問題的方法是在代碼上運行一個分析器,然後讓分析器告訴您哪部分代碼太慢。 –
這段代碼不可能更好的說明一下...從main while循環內移除2個while循環。加入查詢只有** ONE **。我猜主'while'循環在另一個'for'或'foreach'循環中運行......耶穌,這有點耗時,不是嗎?並且'while'中的查詢循環...對不起,這**必須運行緩慢...... – shadyyx
@ moonwave99:完全沒有必要侮辱海報。不要說「這很糟糕」,而要解釋如何改進。如果你不能那樣做,那麼什麼都不要說。 –