繁体   English   中英

如何在Codeigniter中使用多个where子句?

[英]how can i use multiple where clause In codeigniter?

对于我的数据库查询,我必须在Codeigniter PHP中使用多个where子句查询。 我写了这样的代码:

 $this->db->and_where_in('category_name,publication_status','home_headline_sub',1);

但是此查询显示浏览器中的数据库查询错误。 然后我写了这个查询:

$this->db->where('category_name,publication_status','home_headline_sub',1);

但是它仍然给错误。 谁能帮我解决这个问题? 提前致谢。

您可以链接数据库子句,因此可以将其写为

$this->db->where('category_name','case')->where('publication_status','case')->where('home_headline_sub','case');

这将生成查询的WHERE子句,如下所示

// WHERE category_name = 'case' AND publication_status = 'case' AND home_headline_sub = 'case'

此处的文档: http : //ellislab.com/codeigniter/user-guide/database/active_record.html#chaining

您要在其中使用数组。

$this->db->where(array('category_name'=>case,'publication_status'=>case,'home_headline_sub'=>case));

但我想您想对照三栏检查您的价值。 您可以使用

$this->db->or_where(array('category_name'=>1,'publication_status'=>1,'home_headline_sub'=>1));

希望对您有帮助。

//The simple way
$this->db->where('foo_field', 'foo_value')
         ->where('bar_field', 'bar_value')
         ->where('more_field', 'more_value');

//using custom string
//if your sql is really a complex one you can simply write like these

$this->db->where("(foo_filed = 'foo_value') AND (bar_field = 'bar_value') AND (more_field = 'more_value')");

//or may be with something more complex like this
$this->db->where("(foo_filed = 'foo_value') AND ((bar_field = 'bar_value') OR (more_field = 'more_value'))");

//while using a custom string make sure you put them all in the "double quotation marks" and use no ,commas. It is all a single line. The braces are not necessary always but I like to use them.  

文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM