Jump to content

recordset paging


fifin04

Recommended Posts

Hi php guru's out there..

 

just need a little help here with my paging code...okay the code below are the code what I have currently and it works great...

 


<?
[b]//on the top of my page[/b]

//////////////////////////////////////////////////////////////////////

include("dbconnect.php");

///////////////recordset////////////////////////////////////////////
//////FORMATTING RECORDSET///////////////

 $rowsPerPage = 10;
     $pageNum = 1;
     if(isset($_GET['page'])){
        $pageNum = $_GET['page'];  
     }//end if
     $offset = ($pageNum - 1) * $rowsPerPage;

     $query  = "SELECT * FROM tshirt ";           
     $pagingQuery = "LIMIT $offset, $rowsPerPage";
     $result = mysql_query($query . $pagingQuery) or die('Error, query failed');
  
/////////////////////////////////////////////////////////////////////

[size=18][b]//at the bottom page
[/b][/size]

$result  = mysql_query($query) or die('Error, query failed');
$numrows = mysql_num_rows($result);
$maxPage = ceil($numrows/$rowsPerPage);
$self = $_SERVER['PHP_SELF'];

if ($pageNum < $maxPage){

    $page = $pageNum + 1;  
     
    echo "<a href=\"$self?page=$page\">Next</a>\n";

}
echo "$pageNum of $maxPage";

if ($pageNum > 1 && ($pageNum <= $maxPage)){

    $page = $pageNum - 1;
      
    echo "\n\n\n<a href=\"$self?page=$page\">Previous</a>\n";
      
}
?>

 

So the code will paging like this...

 

next 1 of 5 previous  ---->which is okay for a small amount of records

 

but is so annoying for a big amount record because the visitor has to click fo multiple times in order to navigate for particular record...imagine if I have a thousand record...??So what I after is is there possible I can alter my code so that I can output like this for a big amount record...

 

next 1 2 3 4 5 6 7 8 9 previous

 

hope someone will give me some shed on light on how to achieve it....

 

thanks in advanced

 

http://www.bundlecollections.net/paging/paging.zip

Link to comment
https://forums.phpfreaks.com/topic/40864-recordset-paging/
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.