help with pagination
Posted: Thu Jul 02, 2009 7:38 am
so i've been trying to make a photo gallery using a tutorial... the following is my full code for viewing the gallery and images, the problem is I can't get pagination to work, i'm able to display the correct amount of images and the "next" link is there but when i do click next i'm stuck on the same page with the same images, any idea? thanks!
Code: Select all
<?php
include("config.inc.php");
// initialization
$result_array = array();
$counter = 0;
$cid = isset($_GET['cid']) ? (int)($_GET['cid']) : 0;
$pid = isset($_GET['pid']) ? (int)($_GET['pid']) : 0;
// Category Listing
if( empty($cid) && empty($pid) )
{
$number_of_categories_in_row = 5;
$result = mysql_query( "SELECT c.category_id,c.category_name,COUNT(photo_id)
FROM gallery_category as c
LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id
GROUP BY c.category_id" );
while( $row = mysql_fetch_array( $result ) )
{
$result_array[] = "<a href='viewgallery.php?cid=".$row[0]."'>".$row[1]."</a> "."(".$row[2].")";
}
mysql_free_result( $result );
$result_final = "<ul id=\"pselection\">";
foreach($result_array as $category_link)
{
if($counter == $number_of_categories_in_row)
{
$counter = 1;
$result_final .= "\n</tr>\n<tr>\n";
}
else
$counter++;
$result_final .= "<li>".$category_link."</li>";
}
if($counter)
{
if($number_of_categories_in_row-$counter)
$result_final .= "\t<td colspan='".($number_of_categories_in_row-$counter)."'> </td>\n";
$result_final .= "</ul>";
}
}
// Thumbnail Listing
else if( $cid && empty( $pid ) )
{
$number_of_thumbs_in_row = 5;
if(!isset($start)) $start = 0;
$result = mysql_query( "SELECT photo_id,photo_caption,photo_filename FROM gallery_photos
WHERE photo_category='".addslashes($cid)."' LIMIT " . $start . ", 10");
$nr = mysql_num_rows( $result );
if( empty( $nr ) )
{
$result_final = "There are no images in this album. <a href=\"viewgallery.php\">Return to gallery</a>";
}
else
{
while( $row = mysql_fetch_array( $result ) )
{
$result_array[] = "<a href='viewgallery.php?cid=$cid&pid=".$row[0]."'><img src='".$images_dir."/tb_".$row[2]."' border='0' alt='".$row[1]."' /></a>";
}
mysql_free_result( $result );
$result_final = "<ul id=\"gthumb\">";
foreach($result_array as $thumbnail_link)
{
if($counter == $number_of_thumbs_in_row)
{
$counter = 1;
$result_final .= "\n</tr>\n<tr>\n";
}
else
$counter++;
$result_final .= "<li>".$thumbnail_link."</li>";
}
if($counter)
{
if($number_of_photos_in_row-$counter)
$result_final .= "\t<td colspan='".($number_of_photos_in_row-$counter)."'> </td>\n";
$result_final .= "</ul>";
}
}
}
// Full Size View of Photo
else if( $pid )
{
$result = mysql_query( "SELECT photo_caption,photo_filename FROM gallery_photos WHERE photo_id='".addslashes($pid)."'" );
list($photo_caption, $photo_filename) = mysql_fetch_array( $result );
$nr = mysql_num_rows( $result );
mysql_free_result( $result );
if( empty( $nr ) )
{
$result_final = "\t<tr><td>No Photo found</td></tr>\n";
}
else
{
$result = mysql_query( "SELECT category_name FROM gallery_category WHERE category_id='".addslashes($cid)."'" );
list($category_name) = mysql_fetch_array( $result );
mysql_free_result( $result );
$result_final .= "
<a href='viewgallery.php'>Categories</a>>
<a href='viewgallery.php?cid=$cid'>$category_name</a>>
<a href='".$images_dir."/".$photo_filename."' target=\"_blank\" >View full size</a> (Opens in new window/tab)
";
$result_final .= "
<div id=\"gimage\">
<img src='".$images_dir."/".$photo_filename."' alt='".$photo_caption."' width='500;'/>
</div>
<div id=\"caption\">$photo_caption
</div>";
}
}
?>