0

我正在尝试从 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>";
} ?>
4

3 回答 3

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.'"');
.
.
.
.
于 2012-12-21T05:59:14.620 回答
0

像这样使用锚标签

while ($info = mysql_fetch_array($data)) {
    echo "<a href =\"$info[title]\">".$info['title'];. "</a>";
}
于 2012-12-21T05:58:11.050 回答
0

echo '<a href="php page which you want to display on click">$info['descr']</a>'

于 2012-12-21T05:58:41.243 回答