Results 1 to 3 of 3
  1. #1
    Join Date
    May 2013

    Unanswered: Multiple recordset paging

    I have two separate recordsets on a page used.

    the first one 'images' shows only one entry at a time.

    the second one 'images2' shows 6 entries at a time.

    Both of these recordsets have recordset paging, so I can move to the next/previous 'page' (ie if I page 'images' I get another single entry, if I page 'images2' I get the next six etc).

    My problem is that by paging either 'images' or 'images2' resets the other to it's first record..... so if I'm on page 4 of 'images' and then want to page to page 2 'images2', clicking the link causes 'images' to return to page 1 while I do move to page 2 of 'images2'... confused yet?

    I'm guessing what I need to do is combine the recordset paging links together and put them on both links, so that clicking either of the paging links works, but not entirely sure the best way to proceed. Anyone any guidance?

    I'm attaching code for one of the links 'images2' and the code for both recordsets

    many thanks in advance

    Code for link

    HTML Code:
    <?php if ($pageNum_images2 < $totalPages_images2) { // Show if not last page ?>
            <a href="<?php printf("%s?pageNum_images2=%d%s", $currentPage, min($totalPages_images2, $pageNum_images2 + 1), $queryString_images2); ?>"><img src="images/image-controls/right-arrow.png" width="15" height="42" alt=""/></a>
      <?php } // Show if not last page ?>
    Code for 'images'

    HTML Code:
    $maxRows_images = 1;
    $pageNum_images = 0;
    if (isset($_GET['pageNum_images'])) {
      $pageNum_images = $_GET['pageNum_images'];
    $startRow_images = $pageNum_images * $maxRows_images;
    mysql_select_db($database_connection, $connection);
    $query_images = "SELECT * FROM images WHERE gallery = 'art' AND status = 'a' ORDER BY `key` ASC";
    $query_limit_images = sprintf("%s LIMIT %d, %d", $query_images, $startRow_images, $maxRows_images);
    $images = mysql_query($query_limit_images, $connection) or die(mysql_error());
    $row_images = mysql_fetch_assoc($images);
    if (isset($_GET['totalRows_images'])) {
      $totalRows_images = $_GET['totalRows_images'];
    } else {
      $all_images = mysql_query($query_images);
      $totalRows_images = mysql_num_rows($all_images);
    $totalPages_images = ceil($totalRows_images/$maxRows_images)-1;
    code for 'images2'

    HTML Code:
    $maxRows_images2 = 6;
    $pageNum_images2 = 0;
    if (isset($_GET['pageNum_images2'])) {
      $pageNum_images2 = $_GET['pageNum_images2'];
    $startRow_images2 = $pageNum_images2 * $maxRows_images2;
    mysql_select_db($database_connection, $connection);
    $query_images2 = "SELECT * FROM images WHERE gallery = 'art' AND status = 'a' ORDER BY `key` ASC";
    $query_limit_images2 = sprintf("%s LIMIT %d, %d", $query_images2, $startRow_images2, $maxRows_images2);
    $images2 = mysql_query($query_limit_images2, $connection) or die(mysql_error());
    $row_images2 = mysql_fetch_assoc($images2);
    if (isset($_GET['totalRows_images2'])) {
      $totalRows_images2 = $_GET['totalRows_images2'];
    } else {
      $all_images2 = mysql_query($query_images2);
      $totalRows_images2 = mysql_num_rows($all_images2);
    $totalPages_images2 = ceil($totalRows_images2/$maxRows_images2)-1;

  2. #2
    Join Date
    Jan 2007
    Provided Answers: 12
    Your hyperlink needs to set the value of pageNum_images AND pageNum_images2
    Home | Blog

  3. #3
    Join Date
    Apr 2006
    Denver, Co. USA
    Edit: LOL, I though this thread was from March of this year.

    The easiest way of combining sets of GET parameters when building links is to use php's http_build_query() function.

    You can use the existing $_GET array (or a copy of it) as the input array to the http_build_query() function. Each time you set a value to be used in the query string part of a link, set the value in the input array, then just call http_build_query() to use any existing $_GET parameters and the one that you just set a value for.

    For the first snippet of code you posted. this would look like -
    PHP Code:
    // setup only the url query string value(s) that this code is responsible for, leaving all other existing $_GET parameters as is.
    $qs $_GET// make a copy of any $_GET parameters
    $qs['pageNum_images2'] =  sprintf("%d%s"min($totalPages_images2$pageNum_images2 1), $queryString_images2);
    <a href="<?php printf("%s?%s"$currentPagehttp_build_query($qs'''&amp;')); ?>"><img src="images/image-controls/right-arrow.png" width="15" height="42" alt=""/></a>

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts