我有一个页面,显示填充了MySQL数据的表中的日期列表。
我在第1页上显示的字段是
firstname
lastname
email
在第2页,我希望获得该记录的完整信息。
如何创建一个页面,当用户点击firstname
作为<a href="">
链接时,它会自动加载信息而不是为每条记录创建单独的页面?
答案 0 :(得分:0)
您可以尝试将<site 1>?variable=value
附加到您的href,然后通过PHP和?_GET['variable']
例如:
HTML
<a href="site2.php?firstname=foo">Click me!</a>
PHP
<?php echo $_GET['firstname']; ?>
答案 1 :(得分:0)
您可以使用id作为从mysql表中获取的记录的一部分,然后将GET请求发送到第二页,而第二页又取出表中的整个记录...
/**
* ..Establish the connection to MySQL, Selects Database..
* ..Fetch few columns of all records..
*/
$result = mysql_query("SELECT id,firstname,lastname FROM records_table");
//Draw a table to hold the records
echo "<table>";
echo "<tr><th>Firstname</th><th>Lastname</th><th>Email</th><tr>";
while($row = mysql_fetch_assoc($result)){
echo "<tr>";
//Using the id of a record to create ahref link thats sends a get data to the second page
echo "<td><a href='second.php?id=".$row['id']."'>".$row['firstname']."</a></td>";
echo "<td>".$row['lastname']."</td>";
echo "<td>".$row['email']."</td>";
echo "</tr>";
}
echo "</table>";
$record_id = (int) $_GET['id'];
//Fetch the full details of this record...
$result = mysql_query("SELECT * FROM records_table WHERE id = ".$record_id."");
$row = mysql_fetch_assoc($result);
//List out the details..
echo "FIRSTNAME: ".$row['firstname'];
echo "LASTNAME: ".$row['lastname'];
echo "EMAIL: ".$row['email'];
//... as many column you may have...