我正在制作一个摄影网站。在DB中有一个图像表、事件表和类别表,它们通过外键链接。目前,我从数据库中拍摄照片时生成事件,并将它们转换为锚链接。
<?php
while ( $a_row = mysql_fetch_row( $result ) ){
foreach ( $a_row as $field ){
?>
<a href="images.php?event=<?php echo $field;?> "> <php? echo $field; ?> </a>
<?php
}
}
?>单击链接时,脚本从url:/images.php?**event**=eventCalledParty中获取变量
foreach($_GET as $value)
{
$event = $value;
}
$event = mysql_real_escape_string($event);我的问题是-如果我要实现类别并且有一个url,看起来是这样的:
/images.php?event=eventCalledParty&category=categoryCalledFashionPhotography
我将如何将这两个变量从url中分离出来,以便在查询中使用。
谢谢。
发布于 2010-09-15 13:34:41
$event = mysql_real_escape_string($_GET['event']);
$category = mysql_real_escape_string($_GET['category']);发布于 2010-09-15 13:31:25
这些会自动出现在这些变量中..。
$_GET['event']
$_GET['category']PHP为您完成了所有这些工作。
发布于 2010-09-15 13:33:31
在$_GET中,每个url参数都成为一个单独的键。
因此,对于/images.php?event=eventCalledParty&category=categoryCalledFashionPhotography,您将得到:
$_GET['event'] => 'eventCalledParty'
$_GET['category'] => 'categoryCalledFashionPhotography' 你可以采取相应的行动:
if ($_GET['category'] == 'categoryCalledFashionPhotography') {
//do stuff here
}https://stackoverflow.com/questions/3718051
复制相似问题