簡體   English   中英

PHP-創建一頁以加載上一頁中的數據

[英]PHP - create one page that loads data from previous page

我有一個頁面,該頁面在用MySQL數據填充的表中顯示日期列表。

我在第1頁上顯示的字段是

firstname
lastname
email

在第2頁上,我想要記錄的完整信息。

我如何創建一個頁面,當用戶單擊firstname作為<a href="">鏈接時,它會自動加載信息,而不是為每個記錄創建單獨的頁面?

您可以嘗試將<site 1>?variable=value附加到href上,然后通過PHP和?_GET['variable']從第二個站點調用該<site 1>?variable=value

例如:

HTML

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

PHP

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

您可以使用從mysql表獲取的記錄的一部分的id,然后將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頁(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...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM