Recordset Paging with Photo Gallery-keeps jumping-HELP!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
designontime
Forum Newbie
Posts: 3
Joined: Tue Jan 01, 2008 11:28 am

Recordset Paging with Photo Gallery-keeps jumping-HELP!

Post by designontime »

I have created a photo gallery and used the next/previous functions on the page to call the appropriate page. The problem I am having is, when I go to the next page, the thumbnails automatically jump to the first set of thumbnails- they don't stay true to the particular page I am on...which means I essentially have to start over every time I click on a new picture. I am beyond frustrated with this. Any help is appreciated.

The code is below in the next post.
Last edited by designontime on Tue Jan 01, 2008 12:06 pm, edited 1 time in total.
User avatar
Inkyskin
Forum Contributor
Posts: 282
Joined: Mon Nov 19, 2007 10:15 am
Location: UK

Post by Inkyskin »

Without any code I doubt there is much anyone can do to help ;)

One tip though, the thumbnails you have are scaled versions of the large images, and therefore take an age to load. You would be better off providing true smaller versions.
designontime
Forum Newbie
Posts: 3
Joined: Tue Jan 01, 2008 11:28 am

Post by designontime »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Ok thanks, How much of the code do you need?

Code: Select all

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $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";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$currentPage = $_SERVER["PHP_SELF"];

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $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";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$maxRows_gallery_thumb = 15;
$pageNum_gallery_thumb = 0;
if (isset($_GET['pageNum_gallery_thumb'])) {
  $pageNum_gallery_thumb = $_GET['pageNum_gallery_thumb'];
}
$startRow_gallery_thumb = $pageNum_gallery_thumb * $maxRows_gallery_thumb;

mysql_select_db($database_ziva, $ziva);
$query_gallery_thumb = "SELECT * FROM galleries WHERE gallery_name = 'Wedding Portraits' ORDER BY id_gallery ASC";
$query_limit_gallery_thumb = sprintf("%s LIMIT %d, %d", $query_gallery_thumb, $startRow_gallery_thumb, $maxRows_gallery_thumb);
$gallery_thumb = mysql_query($query_limit_gallery_thumb, $ziva) or die(mysql_error());
$row_gallery_thumb = mysql_fetch_assoc($gallery_thumb);

if (isset($_GET['totalRows_gallery_thumb'])) {
  $totalRows_gallery_thumb = $_GET['totalRows_gallery_thumb'];
} else {
  $all_gallery_thumb = mysql_query($query_gallery_thumb);
  $totalRows_gallery_thumb = mysql_num_rows($all_gallery_thumb);
}
$totalPages_gallery_thumb = ceil($totalRows_gallery_thumb/$maxRows_gallery_thumb)-1;

$maxRows_display_this = 1;
$pageNum_display_this = 0;
if (isset($_GET['pageNum_display_this'])) {
  $pageNum_display_this = $_GET['pageNum_display_this'];
}
$startRow_display_this = $pageNum_display_this * $maxRows_display_this;

$colname_display_this = "-1";
if (isset($_GET['id_gallery'])) {
  $colname_display_this = $_GET['id_gallery'];
}
mysql_select_db($database_ziva, $ziva);
$query_display_this = sprintf("SELECT * FROM galleries WHERE id_gallery = %s", GetSQLValueString($colname_display_this, "int"));
$query_limit_display_this = sprintf("%s LIMIT %d, %d", $query_display_this, $startRow_display_this, $maxRows_display_this);
$display_this = mysql_query($query_limit_display_this, $ziva) or die(mysql_error());
$row_display_this = mysql_fetch_assoc($display_this);

if (isset($_GET['totalRows_display_this'])) {
  $totalRows_display_this = $_GET['totalRows_display_this'];
} else {
  $all_display_this = mysql_query($query_display_this);
  $totalRows_display_this = mysql_num_rows($all_display_this);
}
$totalPages_display_this = ceil($totalRows_display_this/$maxRows_display_this)-1;

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

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

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Inkyskin
Forum Contributor
Posts: 282
Joined: Mon Nov 19, 2007 10:15 am
Location: UK

Post by Inkyskin »

On your normal gallery, your query for pagination looks like this:
Now, when you click an image, your link looks like this:
Why not simply combine this together to make:
Replacing the ???'s with the values on the page that you have.
designontime
Forum Newbie
Posts: 3
Joined: Tue Jan 01, 2008 11:28 am

Post by designontime »

I'll give it a whirl
Post Reply