gpt4 book ai didi

php - SQL 查询 : Where, Like, OR - 结合这些

转载 作者:行者123 更新时间:2023-12-04 14:56:59 25 4
gpt4 key购买 nike

在我的数据库中,我有一个名为“model”的表。以下是其中大部分的样子:

iphone 4 16gb white t-mobile

还有一个:

iphone 4 32gb black kpn 

现在我想通过查询来选择那些不同的 iPhone。

$query = mysql_query("SELECT * FROM db WHERE model LIKE '%iphone 4%' AND '%16gb%'") or die(mysql_error());

我希望我的查询查找“iphone 4”,然后查找“16gb”。所以它只输出 16GB 的 iPhone 4。上面的查询不起作用。这是我的语法吗?还是不能这样?

最佳答案

试试这个查询:

SELECT * FROM db WHERE model LIKE '%iphone 4%' AND model LIKE '%16gb%'

SQL 中不能有以下表达式:

model LIKE '%iphone 4%' AND '%16gb%'

您需要完整地陈述两个表达式:

model LIKE '%iphone 4%' AND model LIKE '%16gb%'

关于php - SQL 查询 : Where, Like, OR - 结合这些,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8303172/

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