如果我很笨,请原谅我连续30个小时的编码
所需的最终输出:
SELECT * FROM
cities_extended
WHERE(state_code
= 'MO' ANDcounty
= '格林')或(state_code
= 'NY' ANDcounty
= '格林')
我的尝试:我有此查询(用于测试),我在codeigniter中为其编写了代码,但未能正确地将其转换为codeigniter的Active Record。我知道codeigniter的where_in和or_where_in函数。我尝试了以下代码:
// some code
$counties = $query->result_array();
for($i = 0; $i < count($counties); $i++)
{
$this->db->or_where('county', $counties[$i]['county']);
$this->db->where('state_code', $counties[$i]['state_code']);
}
$this->db->select('zip');
$zips_query = $this->db->get('cities_extended');
return $this->db->last_query();
// some code
这给出了以下输出:
"SELECT `zip` FROM `cities_extended` WHERE `county` = 'Laclede' AND `state_code` = 'MO' OR `county` = 'Greene' AND `state_code` = 'MO' OR `county` = 'Webster' AND `state_code` = 'MO'"
症结:我该如何使用Codeigniter的Active Record输入(县='帮助' AND state_code ='ME')或(县='将' AND state_code ='YOU')。
您可以在以下代码中完成操作
$this -> db -> select('*') -> from ('cities_extended') -> where("(state_code = 'MO' AND county= 'GREENE')") -> or_where("(state_code = 'NY' AND county = 'GREENE')");
$result = $this -> db -> get();
编辑:请执行以下一项
for($i = 0; $i < count($counties); $i++)
{
$this->db->or_where("'county' = '".$counties[$i]['county']."' AND 'state_code' = '".$counties[$i]['state_code."']");
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句