gpt4 book ai didi

php - 将点击的链接传递到另一个页面

转载 作者:行者123 更新时间:2023-11-29 13:12:05 25 4
gpt4 key购买 nike

所以我使用自动完成搜索栏,它返回 2 个结果。我将结果作为链接(不确定这是否正确,如果不正确,请引导我走上正确的路径),并且我需要传递到 nolasam_rec.php 单击了哪个链接。

$query = "SELECT title FROM user_rec WHERE title LIKE '%" . $name . "%'";
$result = mysqli_query($connection, $query);
if (!$result) {
die ("DB query nedarbojas");
}

while ($row = mysqli_fetch_assoc($result)){


echo '<a href=nolasam_rec.php>' . $row['title'] . "</br>" . "</a>";
}

最佳答案

如果您的user_rec中有主键表,例如,user_rec_id ,你可以这样传递:

echo '<a href="nolasam_rec.php?id='.$row['user_rec_id'].'">' . $row['title'] . "</a><br />";

如果您的所有标题都是唯一的,您也可以执行以下操作:

echo '<a href="nolasam_rec.php?title='.urlencode($row['title']).'">' . $row['title'] . "</br>" . "</a>";

在您的 nolasam_rec.php 中,您可以通过 $_GET 访问此信息:

$id = $_GET['id']; // or $_GET['title'];
// then select the record appropriately from the database:
// SELECT * FROM user_rec WHERE user_rec_id=... OR
// SELECT * FROM user_rec WHERE title=...

注意:请阅读 SQL Injections 。这不仅是良好的实践,而且是数据库安全的基本实践。

另请注意:

  1. <br />singleton HTML tag 。这意味着它必须这样写,并在末尾加上斜杠。
  2. 最好输入 <br />结束后标记</a>标签
  3. urlencode()函数用于传递标题。 This function is convenient when encoding a string to be used in a query part of a URL, as a convenient way to pass variables to the next page.

关于php - 将点击的链接传递到另一个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21961566/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com