Here, with one query:
PHP Code:
<?
include('global.php');
$forum_threads = 0;
$count = 0;
echo "<table cellspacing='0' cellpadding='4' border='0'>\n";
echo "<tr><td width='180'><strong>Title</strong></td><td><strong>Your Posts</strong></td><td><strong>Total Replies</strong></td><td><strong>Percentage</strong></td></tr>";
$sqla = "select
forum.forumid
,forum.title
,forum.replycount
,thread.threadid
,post.threadid
, count(post.threadid) as totnu
from forum
left join thread ON forum.forumid=thread.forumid
left join post ON thread.threadid=post.threadid
where forum.allowposting = 1 and forum.forumid != 25 and forum.forumid != 28
AND userid=" . $_GET['userid'] . "
group by post.threadid
order by forum.forumid ASC";
$resulta = mysql_query($sqla) or die(mysql_error());
while ($rowa = mysql_fetch_array($resulta))
{
$forum_threads=$rowa['totnu'];
//now we need to add the number of posts from this thread to the number of posts from the
//other threads in this forum
//now work out the percentage
if ($forum_threads != 0)
{
$percent = (($forum_threads / $rowa['replycount']) * 100);
}
else
{
$percent = "0";
}
echo "<tr><td>" . $rowa['title'] . "</td><td>" . $forum_threads . "</td><td>" . $rowa['replycount'] . "</td><td>" . number_format($percent, 1, '.', '') . "%</td></tr>";
$forum_threads = 0; //reset it.
}
echo "</table>";
?>