I have a dB named "txbDb" I have a table called "txbUpdates", in that table I have the following cols: ID, LOCATION, MODELS, PHOTOGRAPHERS. "LOCATION" refers to a page name or URL; i.e. may1toJun12009.php and ID is simply the current row I'm on, right now I have 46 rows so ID's run 1-46.

I have created the page to output the results to a page named "paging.php" then through an include, I embed the results on my pages that are referenced in the pagination.

I can get the pagination output to list my pages (1-46) and break them into 10 items per page and then use the PREV and NEXT buttons to jump to the next set (1-10, 11-20, etc.) but for the life of me I can't get the current page to display it's corresponding position in the links when called. If I'm on page 14 for example, the links should display 11-20 but they stay on 1-10 no matter which page I'm on.

Big problem is that I've been design webpages for over 15 years and this is the first PHP page I've done and my knowledge of "coding" from the C+ days is long gone from years of non-use. Most of this code is not mine but pulled from web resources, the fix is prob pretty simple but I'm at a loss. If you can pinpoint and fix the code, or have a better code, I'd be much obliged.

<?php require_once(myconnectioncode.php'); ?>
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  return $theValue;

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_updates = 10;
$pageNum_updates = 0;
if (isset($_GET['pageNum_updates'])) {
  $pageNum_updates = $_GET['pageNum_updates'];
$startRow_updates = $pageNum_updates * $maxRows_updates;

mysql_select_db($database_txbDb, $txbDb);
$query_updates = "SELECT * FROM txbUpdates ORDER BY ID asc";
$query_limit_updates = sprintf("%s LIMIT %d, %d", $query_updates, $startRow_updates, $maxRows_updates);
$updates = mysql_query($query_limit_updates, $txbDb) or die(mysql_error());
$row_updates = mysql_fetch_assoc($updates);

if (isset($_GET['totalRows_updates'])) {
  $totalRows_updates = $_GET['totalRows_updates'];
} else {
  $all_updates = mysql_query($query_updates);
  $totalRows_updates = mysql_num_rows($all_updates);
$totalPages_updates = ceil($totalRows_updates/$maxRows_updates)-1;

$queryString_updates = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_updates") == false && 
        stristr($param, "totalRows_updates") == false) {
      array_push($newParams, $param);
  if (count($newParams) != 0) {
    $queryString_updates = "&" . htmlentities(implode("&", $newParams));
$queryString_updates = sprintf("&totalRows_updates=%d%s", $totalRows_updates, $queryString_updates);

<table border="0" align="center" style="margin-top:10px;">
    <td><?php if ($pageNum_updates > 0) { // Show if not first page ?>
        <a href="<?php printf("%s?pageNum_updates=%d%s", $currentPage, 0, $queryString_updates); ?>">First</a>
        <?php } // Show if not first page ?></td>
    <td><?php if ($pageNum_updates > 0) { // Show if not first page ?>
        <a href="<?php printf("%s?pageNum_updates=%d%s", $currentPage, max(0, $pageNum_updates - 1), $queryString_updates); ?>">Previous</a>
        <?php } // Show if not first page ?></td>
        <td><?php do { ?>
<?php echo "<a href=".$row_updates['LOCATION'].">".$row_updates['ID']."</a>" ?>&nbsp;
<?php } while ($row_updates = mysql_fetch_assoc($updates)); ?>
    <td><?php if ($pageNum_updates < $totalPages_updates) { // Show if not last page ?>
        <a href="<?php printf("%s?pageNum_updates=%d%s", $currentPage, min($totalPages_updates, $pageNum_updates + 1), $queryString_updates); ?>">Next</a>
        <?php } // Show if not last page ?></td>
    <td><?php if ($pageNum_updates < $totalPages_updates) { // Show if not last page ?>
        <a href="<?php printf("%s?pageNum_updates=%d%s", $currentPage, $totalPages_updates, $queryString_updates); ?>">Last</a>
        <?php } // Show if not last page ?></td>


Edited by txwebdesign: n/a

7 Years
Discussion Span
Last Post by txwebdesign

I know it's a bit messy but again, it's not my original code. I really don't have time to learn what the issue is so if you want to make a quick $30 just to fix what's broken, then contact me through my email. My sites while not generally offensive, may not be considered appropriate for Daniweb, so drop me an email and I can point you to the active page. I'll be more than happy to arrange a Paypal payment (or some other method if you don't have one) to just fix it. Contact me first though, it should be a fairly quick and easy thing so that's why I'm not offering much and will pay when code is verified.


I appreciate those that took a look but since no takers on it, I assume it's outside the scope of those on here so I'm going to look at one of the freelance coder, job sites for assistance. Thanks much for those that reviewed the issue.

This question has already been answered. 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.