查询PHP,Web开发

时间:2014-04-19 03:59:45

标签: php mysql

我已经建立了与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个值,非常明显!

我尝试过表单,数组,SESSIONS但无济于事。我该如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

href应该是这样的

<a href="nextpage.php?val=<?php echo $data['rowname']; ?>"><?php echo $data['rowname']; ?></a> 

然后在下一页上你可以使用$ _GET ['val']并将其传递给SELECT查询

答案 1 :(得分:0)

尝试以下示例

<强> 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查询进行下一页传递值。

相关问题