我有一个页面,在填充了MySQL数据的表格中显示了日期列表。
我在第 1 页上显示的字段是
firstname
lastname
email
在第 2 页上,我想获得完整的记录信息。
如何创建一个页面,当用户单击firstname
作为<a href="">
链接时,它会自动加载信息,而不是为每条记录创建单独的页面?
您可以使用 id,它是从 mysql 表中获取的记录的一部分,然后将 GET 请求发送到第二页,该页面又获取表中的整个记录...
页 1:
/**
* ..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>";
第 2 页(第二页.php(:
$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...
您可以尝试将<site 1>?variable=value
附加到您的href中,并通过PHP和?_GET['variable']
从第二个站点调用它
例如:
.HTML
<a href="site2.php?firstname=foo">Click me!</a>
.PHP
<?php echo $_GET['firstname']; ?>