Jump to content

Output Rows In Pagination In Descending Manner


itsureboy

Recommended Posts

I want to know how I can sort out my rows when php prints it from MySQL in a descending manner so the last rows I insert in my MySQL table  is displayed on the first page. Right now its displaying it in the order in which it was inserted. Any help please ???. Thank You....

Here is the pagination php code:<br />
[code]
<?php


include 'db.php';


if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}


$max_results = 2;


$from = (($page * $max_results) - $max_results);



$sql = mysql_query("SELECT * FROM pages LIMIT $from, $max_results");

while($row = mysql_fetch_array($sql)){
    // Build your formatted results here.
    echo $row['title'];
}


$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM pages"),0);

$total_pages = ceil($total_results / $max_results);

echo "<tr>";
echo stripslashes("<td class=\"leftnavi2\" colspan=\"1\"> ");
echo "</td>";
echo stripslashes("<td class=\"titlesection2\" colspan=\"4\"> ");


if($page > 1){
    $prev = ($page - 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i ";
        } else {
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
    }
}


if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";
}
echo "</center>";
echo "</td>";
echo "</tr>";
?>

[/code]

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.