2017-05-24 105 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

相關問題