php - 如何正确显示 URL 中具有相同 GET 名称的 PHP/MySQL 的多个参数

标签 php mysql url mysqli parameters

我的参数在 MySQL 数据库中具有不同的名称(tags、tags2、tags3),但使用相同的 GET 方法或换句话说具有相同的列名 (tags)。

代码如下:

$tags = $_GET['tags'];
$tags2 = $_GET['tags'];
$tags3 = $_GET['tags'];

$fetch = mysqli_query($conn, "SELECT * FROM users JOIN user_images ON users.username = user_images.username WHERE tags = '$tags' AND tags = '$tags2' AND tags = '$tags3' ORDER BY users.id DESC");

基本上,我试图在 user_images 表中显示所有带有 3 个不同标签的图像。

这是我的 URL 的样子,但它只显示一个标记而不是全部 3 个:

https://www.example.com/app/user-tags.php?tags=aesthetic&tags2=food&tags3=dogs

第一个参数有效,但不是全部。谁能帮助我哪里出错了?

我考虑过做这样的事情,在查询中包含 tags = aesthetic,food,dogs。但问题是,我认为结果会读作“查找带有 aestheticfooddogs 标签的所有图像”,而不是带有 aesthetic、food 和 dogs 标签的图像。

最佳答案

听起来您想查看表中的 tags 列并找到与 URL 中传递的值相匹配的内容。如果您想查找任何标记值,请将 AND 的使用更改为 OR

$tags  = $_GET['tags'];
$tags2 = $_GET['tags2'];
$tags3 = $_GET['tags3'];

$fetch = mysqli_query($conn, "SELECT * FROM users
JOIN user_images ON users.username = user_images.username
WHERE tags LIKE '%" . $tags  . "%' OR
      tags LIKE '%" . $tags2 . "%' OR
      tags LIKE '%" . $tags3 . "%'
ORDER BY users.id DESC")

关于php - 如何正确显示 URL 中具有相同 GET 名称的 PHP/MySQL 的多个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54725366/

相关文章:

mysql - mysql.user 表中的 max_connections 列有什么用?

python - urllib2.quote 不能正常工作

c# - 如何在不使用 (?) 符号的情况下将参数传递给 rest web 服务?

url - Logstash:为文档创建 url 友好的 _id

php - 使数组与其他数组长度相同?

php - 使用php将数据插入mysql数据库

mysql - 必须声明“RAISERROR”

php - 应该改变这一点并开始使用异常吗?

php - 字体在 HTML 中工作但不呈现 PDF Dompdf v0.8.0

mysql - 将 SQL 粘贴到 MySQL 命令行中