gpt4 book ai didi

mysql - 在逗号分隔的字符串中搜索和获取与来自 URL PHP MySql 的 post 变量匹配的字符串值

转载 作者:行者123 更新时间:2023-11-30 22:08:44 24 4
gpt4 key购买 nike

你好我有一个这样的sql表

id     fname     cat                              address        status

1 Bash Wedding venue ABC a
2 Ashu Wedding venue, Wedding card BCD a
3 jash Wedding venue ABC a
4 hash Wedding venue BCD a
5 Rash Wedding card BCD a

Id "2"有 2 个 cat 值。我想要的是在这两种情况下获取 id“2”,无论 URL 中的 post 变量是“Wedding venue”还是“Wedding cat”。详细说明 URL 是否类似于

www.example.com/list.php?cat=Wedding venue

输出:

id     fname     cat                              address        status

1 Bash Wedding venue ABC a
2 Ashu Wedding venue, Wedding card BCD a
3 jash Wedding venue ABC a
4 hash Wedding venue BCD a

对于 URL

www.example.com/list.php?cat=Wedding card

输出:

id     fname     cat                              address        status

2 Ashu Wedding venue, Wedding card BCD a
5 Rash Wedding card BCD a

最佳答案

使用 LIKE CONCAT():

SELECT * FROM table
WHERE cat LIKE CONCAT('%Wedding venue%')

编辑:

它也可以在没有 concat 的情况下工作:

SELECT * FROM table
WHERE cat LIKE '%Wedding venue%'

但是为了跨 SQL 兼容性(如果你希望明天在不更改代码的情况下切换到另一个 SQL 版本),我建议使用 concat,因为如果请求的编码与表不同,则其他一些 sql 不会比较字符串,而单值 concat那里有一个解决方法。

关于mysql - 在逗号分隔的字符串中搜索和获取与来自 URL PHP MySql 的 post 变量匹配的字符串值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40817089/

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