Jump to content

Recommended Posts

Hi there.

I currently have a working php paginated 'gallery' page that displays 50 records per page.

Which you can then click through to a 'detail page'  to see more info.

 

On this 'detail page' I would then like to allow the user to be able to view the 'previous' or 'next' record, without having to go back to the gallery page.

 

I think I need to change the LIMIT part of the query, However I can't figure out how to switch it from 50 records per page on the gallery page to them take the id of the item over into a new query with 1 item per page.

 

I have attached my gallery query code below.

 

Any help would be appreciated.

 

$maxrows = 50;
$cpage = 0;
if (isset($_GET['cpage'])) {
  $cpage = $_GET['cpage'];
}
$startrow = $cpage * $maxrows;

$query_master = "SELECT * FROM XXXXXXXX WHERE type='XXXXXXXXXXX' ORDER by uniqueid DESC";
$query_limit_master = sprintf("%s LIMIT %d, %d", $query_master, $startrow, $maxrows);
$master = mysql_query($query_limit_master) or die(mysql_error());

if (isset($_GET['totalrows'])) {
  $totalrows = $_GET['totalrows'];
} else {
  $all_master = mysql_query($query_master);
  $totalrows = mysql_num_rows($all_master);
}
$totalPages_master = ceil($totalrows/$maxrows)-1;

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

echo "<ul id=\"portfolio\" class=\"gallery clearfix\">";
while ($row_master = mysql_fetch_array($master)){
   // ********** Start Gallery item *****************
?>
    <li><a href="/lightbox.php?id=<?php echo $row_master['uniqueid']; ?>" rel="lightbox[gallery]"><img src='picture/<?php echo $row_master['filename']; ?>' alt="<?=$row_master['type']?>"></a></li>
<?php

   // ********** End of gallery item *****************
   

   }
   echo "</ul>";

Link to comment
https://forums.phpfreaks.com/topic/194541-pagination-question/
Share on other sites

That is exactly what I initially thought.

 

However its not as simple as that.

 

Say there are 300 results in the query. Thats 6 pages of 50 results. Now say I select 1 item in the gallery to 'view more details' (lets say item 83).

 

On the detail page. I would like to be able to click the next or previous buttons and go to items 82 or 84.

 

How do I format the query to be able to do this? I can create the query no problem to view the individual item. Its how to identify the item in the list of the 300 so that I know what the previous or next item is.

Link to comment
https://forums.phpfreaks.com/topic/194541-pagination-question/#findComment-1023190
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.