我已经连接到mysql数据库,并从表中回显值。
while($data = mysql_fetch_array($res))
{
?>
<a href="nextpage.php"<?php echo $data['rowname'] ?></a>
<?php
}
?> 问题是,当我单击特定的链接时,在nextpage.php上,它应该只显示单击的href值的结果。因此,在nextpage.php上,我定义了类似于SELECT * from tablename where rowname = 'a href value'的东西。
现在发生的事情是,它只显示最后一个rowname值,不管我单击哪个链接,都非常明显!
我尝试过表单、数组、会话,但都没有效果。我该怎么解决这个问题?
发布于 2014-04-19 04:03:21
href应该是这样
<a href="nextpage.php?val=<?php echo $data['rowname']; ?>"><?php echo $data['rowname']; ?></a> 然后在下一页,您可以使用$_GET‘’val‘并传递它来选择查询。
发布于 2014-04-19 04:15:16
尝试下面的示例
page1.php
while($data = mysql_fetch_array($res))
{
echo "<a href='nextpage.php?id=".$data['rowname']." >". $data['rowname'] ."</a>";
}
?> 你的href看起来像nextpage.php?id=[your value]
nextpage.php
$qry = mysql_query("select * from [table_name] where id = ".$_GET['id']."",$con);
while($data = mysql_fetch_array($res))
{
echo $data[0];
}在下一页上,使用$_GET['id']向sql查询传递值。
https://stackoverflow.com/questions/23165634
复制相似问题