我有一个画廊脚本,作为一个新手,我成功地创建了缩略图。我可以点击缩略图来获取大图像,但当我按下“下一个”查看下一个图像时,我会看到'零'图像消息。此图库以'photo_caption'作为主键运行。
以下是我遇到麻烦的代码......
$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>";
这里创建了'left'和'right'箭头,但是当我点击它们时它没有带我到下一个图像。如果我尝试打印$nr
(与单击的photo_caption相对应的行数,等于'1'),当我单击下一个图像的“下一个”箭头时,它变为“0”。这是因为链接不起作用?你可以检查我的代码,看看我在创建链接时是否犯了任何愚蠢的错误吗?请参阅下面该部分的完整代码。
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)
{
$result_final = "\t<tr><td>***No Photo found</td></tr>\n";
}
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>\n\t<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> ";
}
答案 0 :(得分:2)
你的HTML搞砸了,这可能是问题所在,请尝试将'html标记的值包围起来,如下所示:
<a href='viewgallery.php?cname=$cname&pcaption=".str_replace(" ","_",$pid_array[$prev])."'><img src='photos/assets/right.png' border='0'></a>