I have a table of threads, from multiple forums, that i need to sort into 20-thread pages of a specific forum, but I dont know how to do this right. Please, someone tell me whats wrong with this.
This is part of a script. The rest of it works.
$countrows = mysql_query("SELECT * FROM topics WHERE forum='$forum'", $connect);
$numtopics = mysql_num_rows($countrows);
$numpages = $numtopics / 20;
if($numpages < 1)
{
$numpages = 1;
}
$numlast = $numtopics % 20;
if($numlast != 0)
{
$numpages++;
}
//Which topics to display
if($page != 1 && $numtopics > 20)
{
$last = (20 $page) - 20;
$first = 20 $page;
}
if($page == 1 && $numtopics > 20)
{
$last = 1;
$first = 20 - $numlast;
}
if(numtopics <=20)
{
$last = 1;
$first = $numtopics;
}
?>
<CENTER>
<TABLE>
<?
//List the topics
if($addpost == "no" || !$addpost)
{
for($count=$first; count>=$last; $count--)
{
echo "<TR>";
$current++;
$sql3=mysql_query("SELECT FROM topics WHERE number='$current'", $connect);
$thread=mysql_fetch_array($sql3);
if($thread[forum] == $forum)
{
$whatever2=mysql_query("SELECT FROM posts WHERE thread='$thread[title]'", $connect);
$numposts=mysql_num_rows($whatever2);
echo "<TD WIDTH='30%'><A HREF='http://forum.levx.net/postview.php?thread=".$thread[title]."&page=1&addpost=no&forum=".$forum.">".$thread[title]."</A></TD><TD WIDTH='15%'>".$thread[user]."</TD><TD WIDTH='5%'>".$numposts."</TD><TD WIDTH='50%'>".dconvert($thread[date])."</TD>";
}
if($thread[forum] != $forum)
{
$count++;
}
}