Mysql 获取 - HTML 链接的结果指向 table ID

Mysql fetch - results with HTML links points to table ID

我想显示 SQL 结果,每行 html link,其中每个 link 包含 table id。

我的 table 名字:水果

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="link to fetch id 1">apple | tastes good

a href="link to fetch id 2">peach | grows on tree

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

当我说 "link to fetch id 1" 时,我的意思是像 href="www.application.com/another.php 以及一些将获取 ID 1 或 2 或 3 传递给的方法另一个 php 文件。

如何制作这些 link?

如何在另一个 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()

测试它的存在

要使整行 "clickable" 参见 Link entire table row?

顺便说一句:不推荐使用 mysql_* 扩展。选择另一个 API: mysqli 或 PDO_mysql.
参见 http://docs.php.net/manual/en/mysqlinfo.api.choosing.php
当您使用它并且由于您很可能会在另一个查询中使用 _GET['id'] 时,请查看准备好的语句和(命名的)参数。