|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
MySQL fetch loop in descending order?
Code:
$get_comments = mysql_query("SELECT * FROM comments");
while($row = mysql_fetch_array($get_comments))
{
echo 'Nick: ' . $row['nick'] . '<br />';
echo 'Date: ' . $row['date'] . '<br />';
echo 'Comment: ' . $row['comment'] . '<br /><br />';
}
The code above makes a loop that prints records from the first to last row in a table. The table has three columns, id (first row starting from 1), nick and comment. The results looks something like this: Nick: Peter Date: Monday 16th of August 2007 Comment: I am the first comment. Nick: Jimmy Date: Saturday 3rd of October 2007 Comment: I am the second comment. Nick: Sarah Date: Friday 4th of October 2007 Comment: I am the third comment. But I want the rows to come in a descending order, so it'll look like this: Nick: Sarah Date: Friday 4th of October 2007 Comment: I am the third comment. Nick: Jimmy Date: Saturday 3rd of October 2007 Comment: I am the second comment. Nick: Peter Date: Monday 16th of August 2007 Comment: I am the first comment. Any ideas? Thanks in advance! EDIT: Never mind! I friend told me the answer! And if this ever gets indexed by Google, the solution was: Add ORDER BY id DESC in the MySQL query |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > MySQL fetch loop in descending order? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|