douduiyun6125
douduiyun6125
2016-11-03 18:01

如何从foreach循环中隔离的db中删除ci活动记录?

已采纳

This is the function in the CI model:

public function libraryClean() {
    $killCount=0;
    $rows=$this->db->get('mz')->result();
    foreach ($rows as $row) {
        $rID=$row->rID;
        $title=$row->title;
        $char=$title[0];
        if (ctype_lower($char)) {
            $killCount++;
            // delete $row code goes here
        } 
    }
    return $killCount;
}

I've unsuccessfully tried various approaches. Thanks in advance.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • douwen8424 douwen8424 5年前

    You would just use an active record delete query.

    $this->db->delete('mz', array('id' => $rID)); 
    

    Being inside the foreach loop doesn't make the delete any more or less special.

    点赞 评论 复制链接分享