作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的数据库中,我有一个名为“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/
我是一名优秀的程序员,十分优秀!