Jump to content

[SOLVED] Need some pagination help...


A JM

Recommended Posts

I'm having a problem getting a variable to pass from one page to another. I'm using pagination on my site and my goal is to simply pass the variable "pagination=1" once when paging to or from a page on my site.

 

What's happening is the variable is being added each time I page to another page for example I changed pages 3 times and this is what is now being passed.

 

http://xxx.php?pageNum_rstclaimcue=1&totalRows_rstclaimcue=100&pagination=1&pagination=1&pagination=1

 

I've attached the relevant code from the page and hopefully someone can help me solve this.

 

Thanks for any help.

 

A JM,

 

...
$editFormAction = $_SERVER['PHP_SELF'];	//when form is submitted recordset will get adjusted for sorting and dates, etc.

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_rstclaimcue = 15;
$pageNum_rstclaimcue = 0;
if (isset($_GET['pageNum_rstclaimcue'])) {
  $pageNum_rstclaimcue = $_GET['pageNum_rstclaimcue'];
}
$startRow_rstclaimcue = $pageNum_rstclaimcue * $maxRows_rstclaimcue;

mysql_select_db($database_maxdbconn, $maxdbconn);

if ( $_POST['querysubmitted'] == 1) {

//convert the date format from m/d/y => y-d-m
list($month, $date, $year) = explode("/", $_POST['datefrom']);
$queryfrom =  $year . '-' . $month . '-' . $date;
list($month, $date, $year) = explode("/", $_POST['dateto']);
$queryto =  $year . '-' . $month . '-' . $date;

$query_rstclaimcue = "SELECT c.*, u.firstname AS data_first, u.lastname AS data_last, h.firstname AS adj_first, h.lastname AS adj_last FROM claimcue c LEFT JOIN users u ON(c.data_id = u.id) LEFT JOIN users h ON(c.adj_id = h.id) WHERE c." . $_POST['runqueryname'] . " LIKE '%" . $_POST['criteria'] . "%' AND c.new_timestamp BETWEEN '" . $queryfrom . "' AND '" . $queryto . "' ORDER BY c." . $_POST['runqueryname'] . " ASC";

print_r("submitted" . $query_rstclaimcue);

}else{
//default sql
$query_rstclaimcue = "SELECT * FROM claimcue WHERE chk_new=2";
print_r("default" . $query_rstclaimcue);
}

$query_limit_rstclaimcue = sprintf("%s LIMIT %d, %d", $query_rstclaimcue, $startRow_rstclaimcue, $maxRows_rstclaimcue);
$rstclaimcue = mysql_query($query_limit_rstclaimcue, $maxdbconn) or die(mysql_error());
$row_rstclaimcue = mysql_fetch_assoc($rstclaimcue);

if (isset($_GET['totalRows_rstclaimcue'])) {
  $totalRows_rstclaimcue = $_GET['totalRows_rstclaimcue'];
} else {
  $all_rstclaimcue = mysql_query($query_rstclaimcue);
  $totalRows_rstclaimcue = mysql_num_rows($all_rstclaimcue);
}

$totalPages_rstclaimcue = ceil($totalRows_rstclaimcue/$maxRows_rstclaimcue)-1;

$queryString_rstclaimcue = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_rstclaimcue") == false &&
        stristr($param, "totalRows_rstclaimcue") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_rstclaimcue = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_rstclaimcue = sprintf("&totalRows_rstclaimcue=%d%s", $totalRows_rstclaimcue, $queryString_rstclaimcue)."&pagination=1";
?>

Link to comment
Share on other sites

The final line of your code adds "&pagination=1" to your URL, and it will be ran every time. Since before that you also extract out all the old parameters from the original query string, this will obviously keep adding it every time you change page. One solution would be to only add "&pagination=1" if it's not already a parameter. Something like...

 

<?php
if(!in_array("pagination=1", $params)) {
// add &pagination=1
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.