查询PHP,Web开发

I have made a connection to mysql database and echoing values from a table.

while($data = mysql_fetch_array($res))
{
?> 
    <a href="nextpage.php"<?php echo $data['rowname'] ?></a> 
<?php 
}
?> 

Problem is when I click on the particular link, on the nextpage.php, it should display only the result of the value of a href clicked. So on the nextpage.php, I have defined something like SELECT * from tablename where rowname = 'a href value'.

What's happening now is that it displays only the last rowname value regardless of whichever link I click on, very obvious!

I have tried forms, arrays, SESSIONS but to no avail. How do I fix this?

the href should be like this

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

and then on next page you can use $_GET['val'] and pass it to SELECT query

Try example as below

page1.php

while($data = mysql_fetch_array($res))
{
    echo "<a href='nextpage.php?id=".$data['rowname']." >". $data['rowname'] ."</a>";
}
?> 

your href will look like 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];
 }

on nextpage pass value using $_GET['id'] to sql query.