0

我必须通过执行插入操作的同一页面执行编辑/更新操作。我明白了error undefined $select

这是我的方法:

function editCategory($catId,$datavalue)
{
    $data=array(
                'CategoryName' =>    $datavalue['CategoryName'],
                'Status'       =>    $datavalue['Status']
                );

    $this->db->update('tblcategory');
    $this->db->set($data);
    $this->db->where('id',$catId)

    $this->db->select('*');
    $this->db->from('tblcategory');
    $this->db->where('id',$catId);

    $query=$this->db->get()->row(); 

    //$result=$query->row_array(); 
    if($query)
    {
        return $query;
    }
    else
    {
        return false;
    }
}
4

2 回答 2

2

希望对你有帮助 :

update在查询方式中做出正确的子句顺序,where子句set应该在前,应该是这样的:

注意:确保$catId并且$datavalue不是空的,请添加检查

function editCategory($catId, $datavalue)
{
    $data = array(
        'CategoryName' => $datavalue['CategoryName'],
        'Status' => $datavalue['Status']
    );

    $this->db->set($data);
    $this->db->where('id',$catId);
    $this->db->update('tblcategory');


    $this->db->select('*');
    $this->db->from('tblcategory');
    $this->db->where('id',$catId);
    $query=$this->db->get()->row(); 
    if($query)
    {
        return $query;
    }
    else
    {
        return false;
    }
}

更多信息:https ://www.codeigniter.com/user_guide/database/query_builder.html

于 2018-07-25T13:33:17.377 回答
0

简而言之,这是我可以为您提供的帮助。

    function editCategory($catId, $datavalue)
    {
        $data = array(
            'CategoryName' => $datavalue['CategoryName'],
            'Status' => $datavalue['Status']
        );

        //$this->db->set($data); --> you don't need to set it because you already set the values above
        $this->db->where('id',$catId);
        $this->db->update('tblcategory',$data); //pass the data here to be inserted in your table

}
于 2018-07-26T03:40:10.277 回答