将变量从href传递到另一个php页面

时间:2011-03-08 07:46:09

标签: php mysql

。我有这段代码:

<a id="various3" href="picture.php?id=',$pid,'" title="'.$info.'"><img src="picture.php?id=',$pid,'" width="150" height="210"></a>

它将id传递给我的picture.php,我在查询字符串上使用它。

$sql = sprintf("select pics, ext from `06-07` where id='%d'",$_GET['id']);

是否可以使用此方法传递多个变量?因为我想把“dept”和“id”一起传递。如果是这样的话呢?

我试过这个:

<a id="various3" href="picture.php?id=',$pid,'&dept=',$dept,'" title="'.$info.'"><img src="picture.php?id=',$pid,'&dept=',$dept,'" width="150" height="210"></a> 

匹配

$sql = sprintf("select pics, ext from 06-07 where id='%d' AND dept='%s'", $_GET['id'], $_GET['dept']); but it doen't work. what's wrong?

4 个答案:

答案 0 :(得分:9)

<a href="test.php?page_name=<?php echo $this_month; ?>">

通过get方法在另一个页面上访问它:

$file_name = $_GET['page_name'];

答案 1 :(得分:0)

您可以使用&amp;链接获取参数。像这样的标志:

index.php?id=1&depth=2

答案 2 :(得分:0)

是的,可以使用类似

之类的内容在get请求中传递多个参数
picture.php?id=1&dept=xyx&...

但请注意,无论您通过此方式传递的内容都将在浏览器中显示,因此请勿使用此方法传递用户不应知道的内容。

此外,代码中是否有拼写错误?而不是picture.php?id=',$pid,',它应该是picture.php?id=' . $pid . 'picture.php?id=<?php echo $pid; ?>对吗?

答案 3 :(得分:0)

根据您的示例,查询字符串将非常奇怪。

首先,你试图在变量值周围使用单引号。

其次,该行是print / echo语句的一部分吗?现在看起来你根本不打印PHP变量,所以你很可能只是将变量名称作为url的一部分。

假设您给出的示例行不是print / echo语句的一部分:

<a id="various3" href="picture.php?id=<?= $pid ?>&dept=<?= $dept ?>" title="<?= $info ?>"><img src="picture.php?id=<?= $pid ?>&dept=<?= $dept ?>" width="150" height="210"></a>

如果示例行是print / echo语句的一部分:

print '<a id="various3" href="picture.php?id='.$pid.'&dept='.$dept.'" title="'.$info.'"><img src="picture.php?id='.$pid.'&dept='.$dept.'" width="150" height="210"></a>';
相关问题