Jump to content


Photo

Display newest mysql data?


  • Please log in to reply
5 replies to this topic

#1 EvanMartin

EvanMartin
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 11 September 2006 - 05:07 AM

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.....

<?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/\>";
?>


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!

#2 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 11 September 2006 - 07:47 AM

You could do something like:
SELECT * FROM topics ORDER BY id DESC LIMIT 10;
or
SELECT * FROM topics ORDER BY date DESC LIMIT 10;
(date will have to be a timestamp)

#3 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 11 September 2006 - 02:05 PM

Definitely use the latter (though don't call your column "date")... you shouldn't rely on the UIDs being in any order whatsoever.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#4 EvanMartin

EvanMartin
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 11 September 2006 - 08:00 PM

Hmmm, That just about works... but it displays the oldest rather than the newest, Thanks tho  :P

#5 EvanMartin

EvanMartin
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 11 September 2006 - 08:01 PM

Here is the link to the script http://main.synthetic.net.nz/mysql.php

#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 11 September 2006 - 08:34 PM

So you decided to sort by what?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users