Hi Everyone…I have a gallery script where as a newbie I was successful in creating thumbnails and I am able to click on to get the large image. When I press ‘next’ for the next image, I get a ‘zero’ image found message. This gallery runs on ‘photo_caption’ as the primary key.
Here is the bit of code I have trouble with…
$result_final .= "<div class='prevnext'>";
$result_final .= "<span class='prev'><a href=viewgallery.php?cname=$cname&pcaption=".str_replace(" ","_",$pid_array[$next])."><img src=photos/assets/left.png border=0 ></a></span>";
$result_final .= "<span class='next'><a href=viewgallery.php?cname=$cname&pcaption=".str_replace(" ","_",$pid_array[$prev])."><img src=photos/assets/right.png border=0 ></a></span>";
$result_final .= "</div>";
Here the ‘left’ and the ‘right’ arrows are created but when I click on them it is not taking me to the ‘next’ image. If I try to print $nr ( number of rows corresponding to the photo_caption that’s being clicked, which is equal to ‘1’ ) it becomes ‘0’ when I click on the ‘next arrow’ for the ‘next image’. Is this because the link is not working? Can you please check my code to see if I am making any stupid mistakes while creating the link? See the full code of that section below… thank you for your help…
if( $pcaption )
{
$result = mysql_query( "SELECT photo_caption, photo_description, photo_filename,photo_keywords FROM gallery_photos WHERE photo_caption='".addslashes($pcaption)."'" );
list($photo_caption, $photo_description, $photo_filename, $photo_keywords) = mysql_fetch_array( $result );
$nr = mysql_num_rows( $result );
mysql_free_result( $result );
$p_caption = $photo_caption;
$p_description = $photo_description;
$p_keywords = $photo_keywords;
//fill pid_array with sorted pids in current category
$result = mysql_query( "SELECT photo_caption FROM gallery_photos WHERE category_name='".addslashes($cname)."' ORDER BY photo_caption" );
$ct = mysql_num_rows( $result );
while ($row = mysql_fetch_array($result)) {
$pid_array[] = $row[0];
}
mysql_free_result( $result );
#if( empty($nr ) )
if($nr <0)
{
print "%%%%NR is $nr";
$result_final = "\ <tr><td>***No Photo found</td></tr>\
";
}
else
{
$result = mysql_query( "SELECT category_name FROM gallery_category WHERE category_name='".addslashes($cname)."'" );
list($category_name) = mysql_fetch_array( $result );
mysql_free_result( $result );
$result_final = "
<div class=limagePage>
<div class=llink><a href=viewgallery.php>ALBUMS</a><span class=arrow>>></span><a href=viewgallery.php?cname=$cname>$category_name</a></div>
";
// display previous and next links if more than one photo
if ($ct > 1)
{
$key = array_search($pcaption , $pid_array);
$prev = $key - 1;
if ($prev < 0) $prev = $ct - 1;
$next = $key + 1;
if ($next == $ct) $next = 0;
$cname = str_replace(" ","_",$cname);
$pcaption=str_replace(" ","_",$pcaption);
$result_final .= "<div class='prevnext'>";
$result_final .= "<span class='prev'><a href=viewgallery.php?cname=$cname&pcaption=".str_replace(" ","_",$pid_array[$next])."><img src=photos/assets/left.png border=0 ></a></span>";
$result_final .= "<span class='next'><a href=viewgallery.php?cname=$cname&pcaption=".str_replace(" ","_",$pid_array[$prev])."><img src=photos/assets/right.png border=0 ></a></span>";
$result_final .= "</div>";
}
}
$cname = str_replace(" ","_",$cname);
$pcaption=str_replace(" ","_",$pcaption);
$result_final .= "<div class=limage><table><tr><td><table class=image><tr>\
\ <td><a href=viewgallery.php?cname=$cname&pcaption=".str_replace(" ","_",$pid_array[$next])."><img src='".$images_dir."/".$photo_filename."' border='0' alt='".$photo_keywords."' /></a>
<div class=caption>".$photo_caption."</div>
<div class='excerpt'>".$photo_description."</div>
</td>
</tr></table></td></tr></table><div class=underline></div></div>
<!-- .limagePage --></div> ";
}