如何将图像映射区域 ID 发送到 php 文件?

How can i send an image map area id to a php file?

我有一个图像地图,显示存储在 MySQL 数据库中的不同类型食物的类别。类别底部的每个节点都是图像地图上的一个区域,当我单击该区域时,我希望它将该产品的相关产品 ID 发送到名为 show_products.php 的 php 文件,该文件将显示该产品的详细信息(即价格、库存、名称等)

my imagemap

<map name="frozen">
        <area coords="88,172,6,130" shape="rect" id="1001"> 
        <area coords="61,247,143,291" shape="rect" id="1002">
        <area coords="196,132,278,172" shape="rect" id="1003">
        <area coords="237,289,155,249" shape="rect" id="1004">
        <area coords="336,288,253,248" shape="rect" id="1005">
        <area coords="349,248,430,289" shape="rect" id="1006">
    </map>

我已经尝试将地图封装在一个表单中并通过 javascript 提交 POST 数据,但是我的其他 php 文件仍然不会收到与每个区域。我怎样才能将这些唯一的产品 ID 发送到另一个 php 文件,用户在该文件中单击相关区域,show_products.php 页面将显示所选产品的所有详细信息?有没有比使用 id 手动处理每个区域更有效的方法?

如有任何帮助,我们将不胜感激。

谢谢。

您可以将 href 属性添加到您的 <area> 元素并添加通过 php 传递 id 吗?

<area coords="88,172,6,130" href="show_products.php?id=<?= $product_id ?>" shape="rect" id="1001">

然后在您的 show_products.php 中通过

获取 ID
$product_id = $_GET["id"];