optimize this
Posted: Mon Jul 25, 2005 12:50 am
Someone please explain to me why this takes an insane amount of time to load. I've sectioned off the code and this is the part that takes about 15 seconds to load.
Code: Select all
<? $sql_text = ("SELECT id, topicname, threadstatus, author FROM forumtopicmain WHERE forumid = '$forumid' AND type != 'sticky' ORDER BY lastreply DESC");
$query = mysql_query($sql_text) ." LIMIT 0, 25";
// Show the non-stickied topics (most of them)
while($array = mysql_fetch_assoc($query))
{
$replies = mysql_num_rows(mysql_query("SELECT id FROM forumentries WHERE topicid = '".$array['id']."'")) - 1;
$lastpostarray = mysql_fetch_assoc(mysql_query("SELECT time, author FROM forumentries WHERE topicid = '".$array['id']."' ORDER BY time2 DESC LIMIT 1"));
// Show the number of pages for each individual topic
$query2 = mysql_query("SELECT id FROM forumentries WHERE topicid = '".$array['id']."'");
$numberofpages = (int)(((mysql_num_rows($query2) - 1)/25) + 2); ?>
<tr>
<td bgcolor="#E9EBFC" class="main" width="5%" align="center" style="border-left: solid 1px #000000; border-bottom: solid 1px #000000;">
<? if($array['threadstatus'] == "open"){ echo "<img src=\"images/thread_open.gif\" alt=\"Thread Open\">"; } ELSE { echo "<img src=\"images/thread_locked.gif\" alt=\"Thread Locked\">"; } ?>
</td>
<td bgcolor="#E9EBFC" class="main" width="45%" align="left" style="border-left: solid 1px #000000; border-bottom: solid 1px #000000;"><a href="showthread.php?threadid=<? echo $array['id']; ?>&page=1"><? echo stripslashes($array['topicname']); ?></a>
<? if($numberofpages > 2)
{
echo "<BR><font size=1>Page: </font>";
for ($j=1;$j<$numberofpages;$j++)
{
echo "<a href=\"showthread.php?threadid=".$array['id']."&page=$j\">$j</a> ";
}
} ?>
</td>
<td bgcolor="#E9EBFC" class="main" width="10%" align="center" style="border-left: solid 1px #000000; border-bottom: solid 1px #000000;"><B><? echo $replies; ?></B>
</td>
<td bgcolor="#E9EBFC" class="main" width="15%" align="center" style="border-left: solid 1px #000000; border-bottom: solid 1px #000000;"><a href="showme.php?u=<? echo $array['author']; ?>"><? echo $array['author']; ?></a>
</td>
<td bgcolor="#E9EBFC" class="main" width="25%" align="left" style="border-left: solid 1px #000000; border-bottom: solid 1px #000000; border-right: solid 1px #000000;"><? echo $lastpostarray['time']; ?><BR>by <a href="showme.php?u=<? echo $lastpostarray['author']; ?>"><? echo $lastpostarray['author']; ?></a>
</td>
</tr>
<? } ?>