tags:

views:

44

answers:

2

i have one php page with paging option

i use follwoing sql statement to generate total number of pages

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

      $query   = "SELECT COUNT(id) AS numrows FROM TableA"
      $result  = mysql_query($query) or die('Error, query failed');
      $row     = mysql_fetch_array($result, MYSQL_ASSOC);
  $numrows = $row['numrows'];
  $maxPage = ceil($numrows/$rowsPerPage);

now i have follwoing code to write Next / Previous pages link

       $page  = $pageNum - 1;
       $prev  = " <a  href=\"$self?page=$page\" class=\"RedNorm\">[Prev]</a> ";

       $page = $pageNum + 1;
      $next = " <a href=\"$self?page=$page\" class=\"RedNorm\">[Next]</a> ";

my problem is:

when i pass any query sting with page like abc.php?m=1&page=2

that query string will not be available once i click on [Prev] / [Next] page link.

i can undersatnd the problem is in

  $prev  = " <a  href=\"$self?page=$page\" class=\"RedNorm\">[Prev]</a> ";

statement

how can i get page name plus all the query strings on place of $self as this is only getting page name.

Thanks

+2  A: 

Just add the other variables to the link.

If you don't know what they are/might be, you might try something like this:

$q = "?";
foreach($_GET as $k=>$v) {
    if($k == "page") continue;
    $q .= htmlentities($k) . "=" . htmlentities($v) . "&amp;";
}

$page  = $pageNum - 1;
$prev  = " <a  href=\"$self${q}page=$page\" class=\"RedNorm\">[Prev]</a> ";

$page = $pageNum + 1;
$next = " <a href=\"$self${q}page=$page\" class=\"RedNorm\">[Next]</a> ";

That will append all the query string variables to the link, to pass it to the next page.

Mike Caron
nice solution....
air
A: 

You should use $SELF instead of $self.

M42