Php OR 和 AND 条件的查询生成器
Php query builder for OR and AND condition
我这样做是为了构建查询并从 codeigniter
中的 "flights" table 获取席位
$this->load->database();
$this->load->dbforge();
$where = "seatsF>0 OR seatsB>0 OR seatsE>0";
$this->db->where($where);
$this->db->where('approved', 1);
$query=$this->db->get("Flights");
$result=$query->result_array();
echo $this->db->last_query();
die;
return $result;
我当前在 php 中由查询生成器生成的查询是
SELECT * FROM `Flights` WHERE `seatsF` >0 OR `seatsB` >0 OR `seatsE` >0 AND `approved` = 1
但结果也包含 "approved"=0 的结果,我想我的查询正在做的是它得到 1 个 seatsF>0 然后 OR 短路和 returns true 但它不是真正检查整个查询。我如何通过查询生成器生成这样的查询:-
SELECT * FROM `Flights` WHERE `(seatsF` >0 OR `seatsB` >0 OR `seatsE` >0) AND `approved` = 1
您需要将 OR 包含在 () 中。
$where = "(seatsF>0 OR seatsB>0 OR seatsE>0)";
我这样做是为了构建查询并从 codeigniter
中的 "flights" table 获取席位$this->load->database();
$this->load->dbforge();
$where = "seatsF>0 OR seatsB>0 OR seatsE>0";
$this->db->where($where);
$this->db->where('approved', 1);
$query=$this->db->get("Flights");
$result=$query->result_array();
echo $this->db->last_query();
die;
return $result;
我当前在 php 中由查询生成器生成的查询是
SELECT * FROM `Flights` WHERE `seatsF` >0 OR `seatsB` >0 OR `seatsE` >0 AND `approved` = 1
但结果也包含 "approved"=0 的结果,我想我的查询正在做的是它得到 1 个 seatsF>0 然后 OR 短路和 returns true 但它不是真正检查整个查询。我如何通过查询生成器生成这样的查询:-
SELECT * FROM `Flights` WHERE `(seatsF` >0 OR `seatsB` >0 OR `seatsE` >0) AND `approved` = 1
您需要将 OR 包含在 () 中。
$where = "(seatsF>0 OR seatsB>0 OR seatsE>0)";