Page 1 of 1

displaying the last record first

Posted: Mon Apr 19, 2004 8:32 am
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

Posted: Mon Apr 19, 2004 8:34 am
by JayBird
perhap you need a query like this

Code: Select all

SELECT * FROM guestBook ORDER BY date ASC
Mark

Posted: Mon Apr 19, 2004 8:37 am
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.

Posted: Mon Apr 19, 2004 8:40 am
by JayBird
yup, looks good.

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

Mark