php - 将 post 方法数据传递到导航栏而不标签
问题描述
我在导航栏中有一些页面链接在一起。我想使用 post 在它们之间传递信息而不使用tag<intput method='POST'.....>
. 例如,我有带有页面的导航栏:姓名年龄地址。
在页面 Name.php
$query="SELECT code,name FROM people WHERE code=123;
$query_result = pg_query($conn1, $query);
echo '<form action=\"Age.php\" method=\"GET\">' ;
echo 'Reparto:<br>';
while($row = pg_fetch_assoc($query_result)) {
echo '<a href="Age.php code='.$row["code"].'&name='.$row["name"].'">'.$row["name"]. '</a><br>';
};
echo '</form>';
现在我想在导航栏中单击 Age 并在 url 中,我看到使用 post 方法传递的数据。我的解决方案不起作用。我能怎么做?
解决方案
尝试像这样使用http_build_query():
$query="SELECT code,name FROM people WHERE code=123;
$query_result = pg_query($conn1, $query);
//echo '<form action=\"Age.php\" method=\"GET\">' ;
echo 'Reparto:<br>';
while($row = pg_fetch_assoc($query_result)) {
echo '<a href=\"/Age.php?' . http_build_query($row) . '\">' . $row["name"] . '</a><br>';
};
//echo '</form>';
由于这是一个锚点,它会将您重定向到具有所需key=>values
对的特定地址。单击锚点后,您可以使用和获取Age.php
脚本中的所有参数。$_GET['name']
$_GET['code']
这也可以这样做:
<?php
$query="SELECT code,name FROM people WHERE code=123;
$query_result = pg_query($conn1, $query);
?>
Reparto:<br>
<?php while($row = pg_fetch_assoc($query_result)): ?>
<a href="/Age.php?<?= http_build_query($row) ?>"><?= $row["name"] ?></a><br>
<?php endwhile;?>
这是更干净的变体。
推荐阅读
- migration - MS-Access 报告忽略了一些但不是所有 Win-10 PC 的标准
- angular - 通过服务器的 Angular 通用 API 调用
- r - 加入标记回到句子
- javascript - 拖动选定的文本以在网页内复制/移动它?
- sql - 如何列出所有由杰夫·高布伦主演但不包括布鲁斯·威利斯的电影?
- python - 将图像合并到 z-stack 中并在 Python 中进行最大投影 /
- javascript - 如何将数据导入到 gatbsy-config.js
- python - 如何修复所需的位置参数?
- php - 在 WP Shortcode 中显示来自 mySQL 的数据字段
- r - 'Sum' 函数返回 TRUE 或 FALSE 值而不是数字?