1

我有一个画廊脚本,作为一个新手,我成功地创建了缩略图。我可以单击缩略图来获取大图像,但是当我按“下一步”获取下一张图像时,我会收到一条“找到零”图像的消息。此图库以“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>";

这里创建了“左”和“右”箭头,但是当我点击它们时,它并没有将我带到下一个图像。如果我尝试打印$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>&gt;&gt</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>    ";

 } 
4

1 回答 1

2

您的 HTML 搞砸了,这可能是问题所在,请尝试将 '' 放在 html 标签的值周围,如下所示:

<a href='viewgallery.php?cname=$cname&pcaption=".str_replace(" ","_",$pid_array[$prev])."'><img src='photos/assets/right.png' border='0'></a>
于 2013-07-01T00:59:59.493 回答