我是一个新手,试图使用数据库为画廊编写 PHP 脚本。我最近更改了脚本和数据库,以便画廊将基于 'photo_caption. 画廊有效,但如果数据库包含引号(例如标题 Nature's Garden And Colors ),脚本只会拉出引号之前的部分(所以这里只有 Nature 一词而不是整个标题 Nature's Garden And Colors ),从而破坏了链接. 现在链接结构是这样/viewgallery.php?cname=Colorado%20Journies&pcaption=Nature'sGardenAndColors
的,但由于问题,它显示为/viewgallery.php?cname=Colorado%20Journies&pcaption=Nature
有没有解决这个问题的方法?我怎样才能使 $_GET 语句提取完整的 photo_caption 包括引号?谢谢你的帮助...
我现在使用此代码获取链接的图片说明
$pcaption = isset($_GET['pcaption']) ? ($_GET['pcaption']) : 0;
如果($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 ) )
{
print "%%%%NR is $nr";
$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=".$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=".$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=".$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> ";