我试图从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>";
} ?>
答案 0 :(得分:1)
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.'"');
.
.
.
.
答案 1 :(得分:0)
只需使用这样的锚标记
while ($info = mysql_fetch_array($data)) {
echo "<a href =\"$info[title]\">".$info['title'];. "</a>";
}
答案 2 :(得分:0)
echo '<a href="php page which you want to display on click">$info['descr']</a>'