Mysql fetch -结果与HTML链接指向表ID


Mysql fetch - results with HTML links points to table ID

我想显示SQL结果,每行html链接,其中每个链接包含表id。

My table name: fruits

table_id      content      description     price
 ---------------------------------------------------
   1          apple         tastes good    3 usd
   2          peach        grows on tree   4 usd
   3          plump         very purple    1 usd

应该显示

Fruits
apple | tastes good
peach | grows on tree
plump | very purple

(注意:此时我还没有获取价格)

我的代码:

$result = mysql_query("SELECT table_id,content,decription FROM fruits",$conn);
echo table
while ($row = mysql_fetch_row($res)) {
echo "<tr>";     
 echo "<td>" . $row[0] . "</td>";
 echo "<td>" . $row[1] . "</td>";
 echo "<td>" . $row[2] . "</td>";
echo "</tr>";
}
echo "</table>";

我想达到的而不是echo:

a href="获取id 1的链接">苹果|味道不错

a href="获取id 2的链接">桃树长在树上

a href="link to fetch id 3">plump | very purple

当我的意思是"链接到获取id 1",我的意思是像href="www.application.com/another.php和某种方式传递获取id 1或2或3到另一个php文件。

如何创建这些链接?

如何在另一个php文件中捕获传递的id ?

谢谢你的帮助。

类似

while ( false!=($row=mysql_fetch_assoc($res)) ) {
    echo '
        <tr>
            <td><a href="details.php?id=', urlencode($row['table_id']), '">',
                htmlspecialchars($row['content']),
            '</td>
            <td>', htmlspecialchars($row['decription']), '</td>
        </tr>
    ';
}

您将从$_GET['id']中获取details.php中的table_id。首先通过isset()

测试它是否存在

要使整个行"可单击",请参见链接整个表行?

Btw: mysql_*扩展已弃用。选择另一个API: mysqli或PDO_mysql。
见http://docs.php.net/manual/en/mysqlinfo.api.choosing.php
当你在这里,因为你很可能会在另一个查询中使用_GET['id'],看看准备好的语句和(命名的)参数。