Jump to content

Hey Guys . . Quick Pagination question?


Solarpitch

Recommended Posts

Hi,

Ok . . the following is my pagination code...


[code]

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


$query = "SELECT count(*) FROM adds WHERE class = 'Drivers' AND validation = 1";
$result = mysqli_query($mysql_connect, $query) or die (mysqli_error($mysql_connect));


$query_data = mysqli_fetch_row($result);
$numrows = $query_data[0];

$rows_per_page = 2;
$lastpage      = ceil($numrows/$rows_per_page);


$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$query = "SELECT * FROM adds WHERE class = 'Drivers' AND validation = 1 ORDER BY '$orderby' $limit";
$result = mysqli_query($mysql_connect, $query) or die (mysqli_error($mysql_connect));


if ($pageno == 1) {
  echo " FIRST PREV ";
} else {
  echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> ";
  $prevpage = $pageno-1;
  echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> ";
} // if

echo " ( Page $pageno of $lastpage ) ";

for($i = 1; $i <= $lastpage; $i++){
        if($i == $pageno){
            echo($i." ");
        }else{
            echo("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
        }
    }

if ($pageno == $lastpage) {
  echo " NEXT LAST ";
} else {
  $nextpage = $pageno+1;
  echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> ";
  echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> ";
}

[/code]

This code produces the following...

[code]

FIRST PREV ( Page 1 of 5 ) 1 2 3 4 5 NEXT LAST
[/code]

The problem is when you click on a page, it wont jump to that page. Just stays on page 1. The rest seems to work fine. The ideal way I want it is like..


<<Prev 1 2 [3] 4 5 6 7 8... Next>>

I want to limit it to showning 8 results like above, instead of if there were 20 pages, it been like..

<<Prev 1 2 [3] 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Next>>


I appriciate that theres loads of code here, but I would be grateful of some help, cheers.
Link to comment
https://forums.phpfreaks.com/topic/31398-hey-guys-quick-pagination-question/
Share on other sites

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.