Php 执行编辑操作时出错
我必须通过执行插入操作的同一页面执行编辑/更新操作。我得到Php 执行编辑操作时出错,php,codeigniter,codeigniter-3,codeigniter-query-builder,Php,Codeigniter,Codeigniter 3,Codeigniter Query Builder,我必须通过执行插入操作的同一页面执行编辑/更新操作。我得到错误未定义$select 这是我的方法: function editCategory($catId,$datavalue) { $data=array( 'CategoryName' => $datavalue['CategoryName'], 'Status' => $datavalue['Status']
错误未定义$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;
}
}
希望这对您有所帮助: 在
update
query meanswhere
和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;
}
}
更多信息:希望这对您有所帮助: 在
update
query meanswhere
和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;
}
}
更多信息:简而言之,以下是我能为您提供的帮助
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
}
简而言之,以下是我能为您提供的帮助
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
}
但我还想添加一件事,即我必须先编写查询以从数据库获取数据,然后更新查询,否则在获取数据之前,每次都会使用空值进行更新请选中空
$data
,如果不是空值,然后更新,但我还想添加一件事,即我必须先编写查询以从数据库获取数据,然后更新查询,否则在获取数据之前,它每次都会使用空值进行更新请检查空$data
,如果不是,则在此之后更新