Jump to content

Archived

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

AbydosGater

SQL Pulling in order, how out of order? :P

Recommended Posts

Hi, Sorry for the topic name!, bit confusing... But
Heres my script...

[code]
$query = "SELECT * FROM ben_news ORDER BY id";
$result = mysql_query($query);
while($news = mysql_fetch_array($result)) {
$member_id = $news['member_id'];
$author = "SELECT username FROM ben_users WHERE member_id='$member_id'";
$authorresult = mysql_query($author);
$authorinfo = mysql_fetch_array( $authorresult );
echo "<table width='455' border='0' cellspacing='0' cellpadding='0' background='image/longmenu.gif' height='34'>
        <tr>
          <td><FONT FACE='Tahoma'><b>" . $news['title'] . "</b></FONT></td>
        </tr>
      </table> ";
echo "<p>";
echo $news['content'];
echo "</p>";
echo "<p>";
echo "<hr><br>";
echo "Author: &nbsp; " . $authorinfo['username'] . "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; " . "Date/Time:&nbsp; " . $news['timedate'];
echo "</p>";
};

};

[/code]


Right no need to read all of that, but the Important bit is $query = "SELECT * FROM ben_news ORDER BY id";

The id field is an Auto Int.. And it all works fine! but i was wondering how do i get it to order backwards? start with the highest number, 5,4,3,2,1... and so on???

Thanks
Abydos

Share this post


Link to post
Share on other sites
$query = "SELECT * FROM ben_news ORDER BY id ASC";

or

$query = "SELECT * FROM ben_news ORDER BY id DESC";


This link is for you ok.

http://www.1keydata.com/sql/sql-syntax.html

Share this post


Link to post
Share on other sites
good luck but use the link i provided for mysql as it the best ever mysql website for learning i have ever seen.

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.