Can some one expand on this for me as I just want the last topic that was posted in forum to echo or print not all the posts.Using Mysql database.
$query = "SELECT body FROM my table";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
echo " {$row['body']} <br>";
}
?>
Thanks.
echoing last topic posted in my forum
Moderator: General Moderators
Re: echoing last topic posted in my forum
Hey saffron,
You can add some sorting to your SQL statement along with a LIMIT condition:
The ORDER BY code says to sort that column and the DESC means descending (in reverse order). The LIMIT 1 just means to only grab one. You can also use LIMIT #, # .. where the first # means the starting number and the second # means the number of records to grab. So LIMIT 2,3 means start at record 2 and grab 3 total, which means records 2-4.
I hope this helps! Good Luck!
You can add some sorting to your SQL statement along with a LIMIT condition:
Code: Select all
SELECT body FROM my table ORDER BY body DESC LIMIT 1I hope this helps! Good Luck!