[英]Create a clickable link in php from sql results
我正在嘗試從php中的mysql結果可點擊鏈接中獲取結果。 我是php新手,請幫忙。
<?php mysql_connect("localhost", "root", "pass") or die(mysql_error());
mysql_select_db("Branches") or die(mysql_error());
$data = mysql_query("SELECT * FROM items order by ID desc Limit 5") or die(mysql_error());
while ($info = mysql_fetch_array($data)) {
echo $info['title'];
echo " <br>";
echo $info['descr'];
echo "<br>";
echo "<br>";
} ?>
while ($info = mysql_fetch_array($data)) {
echo '<a href="somefile.php?id='.$info['ID'].'">'.$info['title'].'</a>';
echo " <br>";
echo $info['descr'];
echo "<br>";
echo "<br>";
}
然后在somefile.php
,使用$_GET
捕獲ID並顯示結果
$id = $_GET['id'];
// pull info from db based on $id
$sql = mysql_query('SELECT * FROM items WHERE ID = "'.$id.'"');
.
.
.
.
像這樣使用錨標簽
while ($info = mysql_fetch_array($data)) {
echo "<a href =\"$info[title]\">".$info['title'];. "</a>";
}
echo '<a href="php page which you want to display on click">$info['descr']</a>'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.