doutuosai3504 2013-09-06 09:14
浏览 40
已采纳

更新codeigniter中的多个记录

I am working on a CodeIgniter project where i have to change the status of record. Actually I have to update only those records whose id are/is in the ids sting.

Currently, only one record is updated with my code. My model function is:

public function markUnRead() {
    $ids = 1,2,3,4,5,6;
    $update = array('status' => 0);
    $this->db->where_in('id', $ids);
    $this->db->update('tableName',$update);

    if ($this->db->affected_rows() > 0) {
        return true;
    } else {
        return false;
    }
}

Someone help me please.

  • 写回答

1条回答 默认 最新

  • donglian2106 2013-09-06 09:23
    关注

    The second parameter of where_in() method should be an array:

    $this->db->where_in('id', array(1,2,3,4,5,6));
    

    By any reason, if the $ids is an string like "1,2,3,4,5,6", you could get it to work by:

    $ids = explode(',', $ids);
    $this->db->where_in('id', $ids);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料