简体   繁体   English

如何使用PHP / MySQL的相同GET名称正确显示URL中的多个参数

[英]How to correctly display multiple parameters in URL with the same GET name for PHP/MySQL

My parameters have different names ( tags, tags2, tags3 ) but the same GET method or in other words the same column name ( tags ) in the MySQL database. 我的参数在MySQL数据库中具有不同的名称( tags, tags2, tags3 ),但是具有相同的GET方法,或者具有相同的列名( tags )。

Here is the code: 这是代码:

$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");

Basically I am trying to display all images with 3 different tags in the user_images tables. 基本上,我试图在user_images表中显示带有3个不同标签的所有图像。

Here is what my URL looks like, but it only displays one tag and not all 3: 这是我的URL的样子,但是它只显示一个标签,而不是全部3:

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

The first parameter works, but not all of them. 第一个参数有效,但不是全部。 Can anyone help me where I went wrong? 谁能帮助我我哪里出错了?

I thought about doing something likes this, having tags = aesthetic,food,dogs in the query. 我考虑过要做这样的事情tags = aesthetic,food,dogs在查询中添加tags = aesthetic,food,dogs But the problem is that I think the result would read that as, "Find all images with the tags of aestheticfooddogs" instead of tags with aesthetic, food, and dogs. 但是问题在于,我认为结果应该是,“查找带有审美食物标签的所有图像”,而不是带有审美,食物和狗的标签。

It sounds like you want to look in the tags column in your table and find any matches for the values passed in the URL. 听起来您想查看表中的tags列,并找到URL中传递的值的任何匹配项。 If you want to find ANY of the tag values change the use of AND to OR instead. 如果要查找任何标记值,请将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")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM