执行编辑操作时出错

error in performing edit operation

我必须通过执行插入操作的同一页面执行 edit/update 操作。我得到 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;
    }
}

希望对您有所帮助:

Make the correct clause order at update query means where and set clause should come first,应该是这样的:

注意:确保$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

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

    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

}