Jump to content

Realy noob question when sorting mysql results..


Dave2711

Recommended Posts

Hi sorry about this, bit of a silly question but can't for the life of me figure out how to do it..

 

Basically all my entries on my database have a unique ID, and I want my page to sort them in order from highest to lowest. So at the minute with

<?php
$pagenum = $_GET['pagenum'];
if(!isset($pagenum)){ $pagenum = 1; }

$data = mysql_query("SELECT * FROM news") or die(mysql_error());
$rows = mysql_num_rows($data);
$page_rows = 10;
$last = ceil($rows/$page_rows);

if ($pagenum < 1){ $pagenum = 1; }
elseif ($pagenum >= $last){ $pagenum = $last; }


$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; 

$data_p = mysql_query("SELECT * FROM news $max") or die(mysql_error());
$next = $pagenum+1;
while($info = mysql_fetch_array( $data_p ))
{
echo "<tr><td width=100% background=images/bg3.jpg border=1>";
echo "<h3>" . $info['n_title'] . "</h3>";
echo "" . $info['n_dsc'] . "<br>";
echo "<br><b>Author: <font color=#A335EE>" . $info['n_author'] . "</font>  /";
echo "/  Date: <font color=#A335EE>" . $info['n_date'] . "</font></b>";
echo "<br></td></tr>";
}
echo "</table><br><br>";


echo "<center><b> Page $pagenum of $last </b></font><br>";

if ($pagenum == 1)
{
}
else
{
echo "<b>";
echo " ";
echo " ";
$previous = $pagenum-1;
echo "<center><a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>« Newer Posts</a></center></b>";
}


echo "";


if ($pagenum == $last)
{
}
else {

echo " <center><b><a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Older Posts »</a></center>";
echo " ";
echo " ";
}
?>

 

It sorts them in order 1, 2, 3, 4, 5 etc. But id like them to show as 5, 4, 3, 2, 1 as I want it to list news that is stored on the database. Thanks very much in advance

Ahhh, i think i knew that too lol.. thanks very much, think I must have come across it on google and thought it was something else.

 

Thanks again

 

This was actually a MySQL question, which I moved.  If this is resolved please mark as so.

Archived

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

×
×
  • Create New...

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.