2017-05-24 111 views
0

我有一个页面,其中显示了填充了MySQL数据的表中的日期列表。PHP - 创建一个页面,加载前一页的数据

领域我秀第1页是

firstname 
lastname 
email 

在第2页我想有备案的全部信息。

如何创建一个页面,当用户点击firstname作为<a href="">链接时,它会自动加载信息而不是为每条记录创建单独的页面?

+0

通行证,在查询字符串编码格式,并用'$ _GET'的帮助或'$ _REQUEST'抢到就是查询字符串值下页的特定记录ID(MySQL的记录ID)。然后解码该值并在查询中使用以获取记录。 – Narayan

回答

0

您可以使用属于re的部分的id线从MySQL表得到,然后发送一个GET请求到所述第二页面这又取在表中的整个记录​​...

PAGE 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>"; 

PAGE 2(second.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... 
+0

这工作很好,谢谢。 – Boxecutor

+0

然后我如何使用这第二页,然后能够更新或删除记录表单第二页使用ID,并通过其上的形式按钮,它发送到update.php更新按钮'submit'或delete.php对于删除按钮“提交”它似乎选择了该记录 – Boxecutor

0

你可以尝试添加<site 1>?variable=value到您的href,并通过PHP调用,从你的第二个网站,并?_GET['variable']

例如:

HTML

<a href="site2.php?firstname=foo">Click me!</a> 

PHP

<?php echo $_GET['firstname']; ?> 
+0

感谢willove给他们一个尝试看看哪个最适合我喜欢它。 – Boxecutor

相关问题