从sql结果在php中创建一个可点击的链接

时间:2012-12-21 05:52:11

标签: php

我试图从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>";
} ?>

3 个答案:

答案 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>'