使用WHERE子句删除记录



这是我的表:

id    t_id     min      max       range      name
1       2      2         6          2        Peter
2       2      3         5          3        Leofer
3       2      3         5          4        Josh
4       2      3         5          5        Sonny
5       2      2         6          6        Sammy

我想删除PeterSammy的记录。该表中的所有内容都由变量数据组成,因此使用列名将是最佳解决方案。

这是我到目前为止的代码:

for ($x = 0; $x <= sizeof($pick); $x++ )
{
      $where = ('pick_range' < $pick[$x] && 'pick_range' > $pick[$x] );
      $this->db->select('*');
      $this->db->where('teaser_id',$first_page_data['teaser_id']);
      $this->db->where('sb_id',$sbid);
      $this->db->where('pick_range ', $where);
      $query = $this->db->get('tbl_name');
      if($query->num_rows() == 1);
      {
        $this->db->where('pick_range',$where);
        $this->db->where('teaser_id',$first_page_data['teaser_id']);
        $query = $this->db->delete('tbl_name');
    }
}

有没有其他简单的方法可以做到这一点?

你可以试试这个:

for ($x = 0; $x <= sizeof($pick); $x++ )
{
    $this->db->trans_start();
    $where = ('pick_range' < $pick[$x] && 'pick_range' > $pick[$x] );
    //$this->db->select('*');
    $this->db->where('teaser_id',$first_page_data['teaser_id']);
    $this->db->where('sb_id',$sbid);
    $this->db->where('pick_range ', $where);
    //$query = $this->db->get('tbl_name');
 //if($query->num_rows() == 1);
 //{
    $this->db->where('pick_range',$where);
    $this->db->where('teaser_id',$first_page_data['teaser_id']);
    $this->db->delete('tbl_name');
    $this->db->trans_complete();
    return TRUE;
 //}
}

这将删除与WHERE子句匹配的数据。

最新更新