displaying the last record first

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
tiresome
Forum Newbie
Posts: 16
Joined: Sun Apr 18, 2004 9:45 am

displaying the last record first

Post by tiresome »

I am using this to display the list of guests who has signed my guest book but the problem is the guest who signed the book most recently goes to the very bottom of the page. Here's part of the code that I wrote:

Code: Select all

<?php
$result = mysql_query('select  * from guestBook ;');
$num_results = mysql_num_rows($result);

  echo '<p>Number of guests found: '.$num_results.'</p>';

  for ($i=0; $i <$num_results; $i++)
  {
     $row = mysql_fetch_array($result);
     echo '<p><strong>'.($i+1).'. Name: ';
     echo htmlspecialchars(stripslashes($row['name']));
     echo '</strong>';
     echo '<br />Location: ';
     echo stripslashes($row['location']);
     echo '<br />Email: ';
     echo stripslashes($row['email']);
     echo '<br />URL: ';
     echo stripslashes($row['url']);
     echo '<br />Comments: ';
     echo stripslashes($row['comments']);
 }


?>
I have got a mental block really. The answer is probably very simple but right now I just can't seem to think at all hehe :D
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

perhap you need a query like this

Code: Select all

SELECT * FROM guestBook ORDER BY date ASC
Mark
tiresome
Forum Newbie
Posts: 16
Joined: Sun Apr 18, 2004 9:45 am

Post by tiresome »

That's neat. It's working now. Muchas gracias amigo :D This is what I wrote:

Code: Select all

<?php
$result = mysql_query('select  * from guestBook order by created desc ;');


?>
Here create is actually defined as timestamp in MySql which is exactly what you said, right? Righteo, cheerz mate.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

yup, looks good.

You are right, need to use DESC, my bad :)

Mark
Post Reply