reversing order of mysql results

Associate
Joined
11 Oct 2008
Posts
268
I'm trying to edit someone elses code to reverse the mysql results but im not having much luck. If its simple would someone mind telling me how to do it please.

I will keep google'ing it to try and find the answer myself in the mean time.

heres the code

PHP:
<?php
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}

$sql = 'SELECT id, name, url FROM newsletters';
mysql_select_db('oakfarm');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
echo <<<DB
     
         <img src="img/1.gif"> NAME: $row[name] <br> 

         <img src="img/1.gif"> <a href="$row[url]">DOWNLOAD / VIEW</a> <br> 

         <img src="img/1.gif"> <a href="?nav=manage_newsletters&delete=yes&id=$row[id]&name=$row[name]">DELETE</a> <br> 

        -----------------------------------------<br><br>

DB;

} 

?>
 
You will want to use the order by and sort commands. For example, assuming you want to order by the name column the above query would become

Code:
SELECT id, name, url 
FROM newsletters 
ORDER by name

The default sort is ascending, to reverse the order add (descending) add the DESC keyword

Code:
SELECT id, name, url 
FROM newsletters 
ORDER by name DESC
 
Back
Top Bottom