Jump to content

Archived

This topic is now archived and is closed to further replies.

EvanMartin

Display newest mysql data?

Recommended Posts

Im making a script to display the newest threads from my forum. I need to know how i can get the newest threads names in order.

Here's what i have so far.....

[quote]<?php
mysql_connect("********", "*******", "*******") or die(mysql_error());
mysql_select_db("******") or die(mysql_error());

$forum_post = mysql_query("SELECT * FROM forum_thread")
or die(mysql_error()); 

while($row = mysql_fetch_array( $forum_post )) {
$topic1 = $row['title'];
$topic2 = $row['title'];
$topic3 = $row['title'];
$topic4 = $row['title'];
$topic5 = $row['title'];
$topic6 = $row['title'];
$topic7 = $row['title'];
}

echo "<table border='1'>";
echo "<tr> <th colspan=\"2\">&nbsp;Recent Forum Threads</tr><tr>";
echo "<tr> <th><img src='http://homepages.xnet.co.nz/~jems.martin/images/arrow.gif'></th> <th>$topic1</th> </tr>";
echo "<tr> <th><img src='http://homepages.xnet.co.nz/~jems.martin/images/arrow.gif'></th> <th>$topic2</th> </tr>";
echo "<tr> <th><img src='http://homepages.xnet.co.nz/~jems.martin/images/arrow.gif'></th> <th>$topic3</th> </tr>";
echo "<tr> <th><img src='http://homepages.xnet.co.nz/~jems.martin/images/arrow.gif'></th> <th>$topic4</th> </tr>";
echo "<tr> <th><img src='http://homepages.xnet.co.nz/~jems.martin/images/arrow.gif'></th> <th>$topic5</th> </tr>";
echo "<tr> <th><img src='http://homepages.xnet.co.nz/~jems.martin/images/arrow.gif'></th> <th>$topic6</th> </tr>";
echo "<tr> <th><img src='http://homepages.xnet.co.nz/~jems.martin/images/arrow.gif'></th> <th>$topic7</th> </tr>";
echo "</table>";
echo "<P/\>";
?>[/quote]

That displays the newest thread fine but dosent display the the 2nd newest 3rd newest 4th newest ect
Any help will be greatly appreciated..

Thanks Evan!

Share this post


Link to post
Share on other sites
You could do something like: [code]SELECT * FROM topics ORDER BY id DESC LIMIT 10;[/code] or [code]SELECT * FROM topics ORDER BY date DESC LIMIT 10;[/code] (date will have to be a timestamp)

Share this post


Link to post
Share on other sites
Definitely use the latter (though don't call your column "date")... you shouldn't rely on the UIDs being in any order whatsoever.

Share this post


Link to post
Share on other sites
Here is the link to the script [url=http://main.synthetic.net.nz/mysql.php]http://main.synthetic.net.nz/mysql.php[/url]

Share this post


Link to post
Share on other sites
So you decided to sort by what?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.