0
<?
include_once('config.php');

?>
<?
//-----------------------------------------------
//PAGING STARTS FROM HERE
//-----------------------------------------------
// how many rows to show per page

$rowsPerPage = 12;
$productsPerRow = 1;
// by default we show first page
$pageNum = 1;

// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
    $pageNum = $_GET['page'];
}

// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;

// how many rows we have in database

$prdrs=mysql_query("Select * from products where sub_cat_id='$id'");
$numrows=mysql_num_rows($prdrs);
$total_prds=$numrows;

// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
if($maxPage==0) {
$maxPage=1;
}else{
$maxPage=$maxPage;
}

$self = $_SERVER['PHP_SELF']."?id=$id";
$prdrs=mysql_query("Select * from products where sub_cat_id='$id' ORDER BY sorting_order LIMIT $offset, $rowsPerPage");


?>

===================================
Part 2 script of page numbers
===================================

<?
            if ($pageNum > 1)
{
    $page = $pageNum - 1;
    $prev = " <a href=\"$self&page=$page\"id=\"no\">Back</a>&nbsp; ";
    
    $first = " <a href=\"$self&page=1\"no=\"no\">[First Page]</a> ";
} 
else
{
    $prev  = '  ';       // we're on page one, don't enable 'previous' link
    $first = ' '; // nor 'first page' link
    
  //  $prev  = ' [Prev] ';  
    //$first = ' [First Page] ';
}

// print 'next' link only if we're not
// on the last page
if ($pageNum < $maxPage)
{
    $page = $pageNum + 1;
    $next = " <a href=\"$self&page=$page\" id=\"no\">Next</a>";
    
    $last = " <a href=\"$self&page=$maxPage\"id=\"no\">[Last Page]</a> ";
} 
else
{
    $next = ' [Next] ';      // we're on the last page, don't enable 'next' link
    $last = ' [Last Page] '; // nor 'last page' link
    
    $next = ' '; 
    $last = ' ';
}

// print the page navigation link
if ($total_prds > $rowsPerPage){
?>
            <table width="89" height="19" border="0" cellpadding="0" cellspacing="0" id="no">
              <tr>
                <td width="33%" align="center" id=""><?
echo $first;
?></td>
<td width="33%" align="center" id=""><?
echo $prev;
?></td>
                <td width="33%" align="center" id="no"><? 
for($pi=1; $pi<=$maxPage; $pi++){
echo "<a href=\"$self&page=$pi\"id=\"no\">";
if($pageNum==$pi){
echo "<span id=\"yes\">";
echo $pi."</span>";
}else{
echo "<span id=\"no\">";
echo $pi."</span>";
}

echo "</a>";
}
?></td>
                <td width="33%" align="center" id=""><?
echo  $next;
?></td><td width="33%" align="center" id=""><?
echo  $last;
?></td>
              </tr>
            </table>
          <? 
}
            
            ?>

========================================================================================
if total pages are 29 the its is like this
[First Page] [back] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 [Next][Last Page]
but i want like this
[First Page] [back] 1 2 3 4 5 6 7 8 9 10 11 ....[Next][Last Page]
================================================================================
Please e-mail me if you can at info@detelli.net

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by detelli
0

Try to limit the records for each page. And pass the parameter via the pagination link and use these parameters for retrieving records. There is some ways for this process and you can choose your convenient way.

0

actually i have no idea that how to limit page numbers. kindly ready this script for use

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.