Search Webmaster Help and Solution

[RESOLVED] Pagination solution, I think

Hi All,

I am working on a project that out puts data to a table from an SQL database.

I need to output 15 records at a time and display them for a set period, and then automatically rollover to the next page.

I know how to set the code up to create x number of page per record set but I am completely stuck on how to automatically rollover to the next page. The code for creating the x number of page per record set is below. Can anyone point me in the right direction as to how I can accomplish this task.

The code I am using to extract the data and create the x number of pages.
PHP Code: $maxRows_fids = 10;
$pageNum_fids = 0;
if (isset($_GET[pageNum_fids])) {
  $pageNum_fids = $_GET[pageNum_fids];
}
$startRow_fids = $pageNum_fids * $maxRows_fids;

mysql_select_db($database_flightq, $flightq);
$query_fids = SELECT * FROM flightdata WHERE ArrivalOrDeparture = O  ORDER BY ScheduledDateTime ASC;
$query_limit_fids = sprintf(%s LIMIT %d, %d, $query_fids, $startRow_fids, $maxRows_fids);
$fids = mysql_query($query_limit_fids, $flightq) or die(mysql_error());
$row_fids = mysql_fetch_assoc($fids);

if (isset($_GET[totalRows_fids])) {
  $totalRows_fids = $_GET[totalRows_fids];
} else {
  $all_fids = mysql_query($query_fids);
  $totalRows_fids = mysql_num_rows($all_fids);
}
$totalPages_fids = ceil($totalRows_fids/$maxRows_fids)-1;

$currentPage = $_SERVER[PHP_SELF];

$queryString_fids = ;
if (!empty($_SERVER[QUERY_STRING])) {
  $params = explode(&, $_SERVER[QUERY_STRING]);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, pageNum_fids) == false &&
        stristr($param, totalRows_fids) == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_fids = & . htmlentities(implode(&, $newParams));
  }
}
$queryString_fids = sprintf(&totalRows_fids=%d%s, $totalRows_fids, $queryString_fids);
The code I am using to create the static "back" and "forward" buttons which I am trying to make automatic.
PHP Code: <table border=0>
  <tr>
    <td><?php if ($pageNum_fids > 0) { // Show if not first page ?>
          <a href=<?php printf(%s?pageNum_fids=%d%s, $currentPage, 0, $queryString_fids); ?>>First</a>
          <?php } // Show if not first page ?>
    </td>
    <td><?php if ($pageNum_fids > 0) { // Show if not first page ?>
          <a href=<?php printf(%s?pageNum_fids=%d%s, $currentPage, max(0, $pageNum_fids - 1), $queryString_fids); ?>>Previous</a>
          <?php } // Show if not first page ?>
    </td>
    <td><?php if ($pageNum_fids < $totalPages_fids) { // Show if not last page ?>
          <a href=<?php printf(%s?pageNum_fids=%d%s, $currentPage, min($totalPages_fids, $pageNum_fids + 1), $queryString_fids); ?>>Next</a>
          <?php } // Show if not last page ?>
    </td>
    <td><?php if ($pageNum_fids < $totalPages_fids) { // Show if not last page ?>
          <a href=<?php printf(%s?pageNum_fids=%d%s, $currentPage, $totalPages_fids, $queryString_fids); ?>>Last</a>
          <?php } // Show if not last page ?>
    </td>
  </tr>
</table> Many thanks in advance. Hi All,

I am working on a project that out puts data to a table from an SQL database.

I need to output 15 records at a time and display them for a set period, and then automatically rollover to the next page.

I know how to set the code up to create x number of page per record set but I am completely stuck on how to automatically rollover to the next page. The code for creating the x number of page per record set is below. Can anyone point me in the right direction as to how I can accomplish this task.

The code I am using to extract the data and create the x number of pages.
PHP Code: $maxRows_fids = 10;
$pageNum_fids = 0;
if (isset($_GET[pageNum_fids])) {
  $pageNum_fids = $_GET[pageNum_fids];
}
$startRow_fids = $pageNum_fids * $maxRows_fids;

mysql_select_db($database_flightq, $flightq);
$query_fids = SELECT * FROM flightdata WHERE ArrivalOrDeparture = O  ORDER BY ScheduledDateTime ASC;
$query_limit_fids = sprintf(%s LIMIT %d, %d, $query_fids, $startRow_fids, $maxRows_fids);
$fids = mysql_query($query_limit_fids, $flightq) or die(mysql_error());
$row_fids = mysql_fetch_assoc($fids);

if (isset($_GET[totalRows_fids])) {
  $totalRows_fids = $_GET[totalRows_fids];
} else {
  $all_fids = mysql_query($query_fids);
  $totalRows_fids = mysql_num_rows($all_fids);
}
$totalPages_fids = ceil($totalRows_fids/$maxRows_fids)-1;

$currentPage = $_SERVER[PHP_SELF];

$queryString_fids = ;
if (!empty($_SERVER[QUERY_STRING])) {
  $params = explode(&, $_SERVER[QUERY_STRING]);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, pageNum_fids) == false &&
        stristr($param, totalRows_fids) == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_fids = & . htmlentities(implode(&, $newParams));
  }
}
$queryString_fids = sprintf(&totalRows_fids=%d%s, $totalRows_fids, $queryString_fids);
The code I am using to create the static "back" and "forward" buttons which I am trying to make automatic.
PHP Code: <table border=0>
  <tr>
    <td><?php if ($pageNum_fids > 0) { // Show if not first page ?>
          <a href=<?php printf(%s?pageNum_fids=%d%s, $currentPage, 0, $queryString_fids); ?>>First</a>
          <?php } // Show if not first page ?>
    </td>
    <td><?php if ($pageNum_fids > 0) { // Show if not first page ?>
          <a href=<?php printf(%s?pageNum_fids=%d%s, $currentPage, max(0, $pageNum_fids - 1), $queryString_fids); ?>>Previous</a>
          <?php } // Show if not first page ?>
    </td>
    <td><?php if ($pageNum_fids < $totalPages_fids) { // Show if not last page ?>
          <a href=<?php printf(%s?pageNum_fids=%d%s, $currentPage, min($totalPages_fids, $pageNum_fids + 1), $queryString_fids); ?>>Next</a>
          <?php } // Show if not last page ?>
    </td>
    <td><?php if ($pageNum_fids < $totalPages_fids) { // Show if not last page ?>
          <a href=<?php printf(%s?pageNum_fids=%d%s, $currentPage, $totalPages_fids, $queryString_fids); ?>>Last</a>
          <?php } // Show if not last page ?>
    </td>
  </tr>
</table> Many thanks in advance.

View Complete Thread with Replies

Related Items

Query failed: connection to localhost:3354 failed (errno=111, msg=Connection refused).