php - mySQL 查询 WHERE...OR... 快捷方式

标签 php mysql codeigniter activerecord

是否有编写以下 mySQL 查询的快捷方式?我正在寻找压缩的速记

SELECT * FROM `listings` where `bedroom` = 1 OR `bedroom` = 2

因为我想让在 PHP 中动态构建 mySQL 查询变得更容易。类似于 WHERE bedroom = 1, 2 因为我从 PHP 获得的数字在数组 bedroom[1] = 1, bedroom[2] = 1 中。

SELECT * FROM `listings` where `bedroom` = 1 OR `bedroom` = 2;

而且因为我使用的是 Codeigniter,Active Record 中的一些快捷方式也很棒!

最佳答案

我不太明白你在问什么;您需要更短的查询吗?
如果是这样,试试这个:

SELECT * FROM listings WHERE bedroom IN (1,2)

关于php - mySQL 查询 WHERE...OR... 快捷方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8023424/

相关文章:

javascript - 确认框不显示并自动删除

python - Django更新MySQL数据库涉及外键的问题

mysql - 对多于 1 列的 Oracle 查询执行 JOIN

php - Codeigniter 将参数传递给 Controller ​​索引

Windows : no errors, 上的 PHP mail() 未发送电子邮件

PHP/SQL - 查询数组加载时间

php - 如何根据mysql返回的不同值显示php结果

mysql - 如何使用我的站点目录中的现有文件创建 WordPress 数据库文件?

php - Codeigniter 2 的自定义表单验证错误消息

PHP:在报告中显示 WMS 的按日期库存