PDA

View Full Version : Recent Posts Fetching Problem


Infinite Guitar
09-17-2007, 01:42 PM
Hi everyone!

My programmer setup this code to fetch the thread title and username of the latest 8 posts in the forum, but it's acting really weird. It's randomly showing different amounts of recent posts, from none to 3 to 6, when it should always show 8. And it's putting the incorrect thread title over the usernames. It's just acting really weird. Can anyone check out the below code and tell me if you notice anything that needs to be changed?

Thanks so much for any help guys,
Sean

CODE:

<?php
$numberOfPosts = 8;
$rs= mysql_query("SELECT postid, username, title, threadid FROM post ORDER BY dateline DESC LIMIT $numberOfPosts");
while ($row= mysql_fetch_array($rs))
{
if ($row['title']=='')
{
$threadid= $row['threadid'];
$rs2= mysql_query("SELECT title FROM post WHERE postid=$threadid LIMIT 1");
$row2= mysql_fetch_array($rs2);
if ($row2 && $row2['title'])
{
$row['title']= $row2['title'];
}
else
{
continue;
}
}

echo "<tr><td class='red10arial'><a class='whitetogray10' href='/forum/showthread.php?t={$row['threadid']}'>";
echo $row['title'].'</a><br/>'.$row['username'].'';
echo '</td></tr>';
}
?>

Opserty
09-17-2007, 02:39 PM
SELECT title FROM post WHERE postid=$threadid LIMIT 1
FROM post should be FROM thread (I think, or is it "threads" I'm not to sure)

Also you can remove this:

else
{
continue;
}


Finally use the PHP BBCode tags when you post PHP code :p