multiple where condition codeigniter [英] multiple where condition codeigniter

查看:147
本文介绍了multiple where condition codeigniter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将此查询转换为有效记录?

 UPDATE table_user 
SET email ='$ email ',last_ip ='$ last_ip'
其中username ='$ username'和status ='$ status';

我试图将上面的查询转换为:

  $ data = array('email'=> $ email,'last_ip'=> $ ip); 
$ this-> db-> where('username',$ username);
$ this-> db-> update('table_user',$ data);

如何使用clausa状态?

 #必须写db->其中两次这样吗? 
$ this-> db-> where('username',$ username);
$ this-> db-> where('status',$ status);

我也尝试过:

  $ this-> db-> where('username',$ username,'status',$ status); 


解决方案

可以使用数组并传递数组。 / p>

http://codeigniter.com /user_guide/database/active_record.html#select

 关联数组方法:
$ array = array ('name'=> $ name,'title'=> $ title,'status'=> $ status);

$ this-> db-> where($ array);

//产生:WHERE name ='Joe'AND title ='boss'AND status ='active'

或如果您要执行除比较之外的其他操作

  $ array = array('name!='=> $ name,'id<'=> $ id,'date>'=> $ date); 

$ this-> db-> where($ array);


How can I convert this query to active record?

"UPDATE table_user 
 SET email = '$email', last_ip = '$last_ip' 
 where username = '$username' and status = '$status'";

I tried to convert the query above to:

$data = array('email' => $email, 'last_ip' => $ip);
$this->db->where('username',$username);
$this->db->update('table_user',$data);

How about using the where clausa status?

# must i write db->where two times like this?
$this->db->where('username',$username);
$this->db->where('status',$status);

I also tried this:

$this->db->where('username',$username,'status',$status);

解决方案

you can use an array and pass the array.

per the user guide: http://codeigniter.com/user_guide/database/active_record.html#select

Associative array method:
$array = array('name' => $name, 'title' => $title, 'status' => $status);

$this->db->where($array); 

// Produces: WHERE name = 'Joe' AND title = 'boss' AND status = 'active'

Or if you want to do something other than = comparison

$array = array('name !=' => $name, 'id <' => $id, 'date >' => $date);

$this->db->where($array);

这篇关于multiple where condition codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆