Php 为什么不能先选择查询,然后再编辑查询
此web应用程序是一个包含成员数据的表,如果单击“编辑”,它将链接到已选择成员数据的编辑页面,因此应首先选择该页面 但是 为什么选择查询不能先写后写编辑查询。 我试图将选择部分代码移到上面,但当运行程序时,它无法编辑(不工作) 注:如果我像下面这样写,效果很好。但我想知道原因Php 为什么不能先选择查询,然后再编辑查询,php,sql,database,codeigniter,Php,Sql,Database,Codeigniter,此web应用程序是一个包含成员数据的表,如果单击“编辑”,它将链接到已选择成员数据的编辑页面,因此应首先选择该页面 但是 为什么选择查询不能先写后写编辑查询。 我试图将选择部分代码移到上面,但当运行程序时,它无法编辑(不工作) 注:如果我像下面这样写,效果很好。但我想知道原因 public function editMember($id) { //UPDATE if($this->input->post("btn") != null) { $
public function editMember($id)
{
//UPDATE
if($this->input->post("btn") != null)
{
$arr = array(
"name" => $this->input->post('member_name'),
"email" => $this->input->post('email'),
"tel" => $this->input->post('phone')
);
$this->db->where("id", $id);
$this->db->update('member', $arr);
redirect("member", "refresh");
exit();
}
$sql = "SELECT * FROM member WHERE id = $id"; //SELECT
$rs = $this->db->query($sql);
if($rs->num_rows() == 0) //check the exist of data
{
$result['fetch'] = array();
}
else
{
$data['fetch'] = $rs->row_array(); // just fetch one row
return $data['fetch'];
}
}
Try this code
public function editMember($id)
{
$sql = "SELECT * FROM member WHERE id = $id"; //SELECT
$rs = $this->db->query($sql);
//UPDATE
if($this->input->post("btn") != null)
{
$arr = array(
"name" => $this->input->post('member_name'),
"email" => $this->input->post('email'),
"tel" => $this->input->post('phone')
);
$this->db->where("id", $id);
$this->db->update('member', $arr);
redirect("member", "refresh");
exit();
}
if($rs->num_rows() > 0) //check the exist of data
{
$data['fetch'] = $rs->row_array(); // just fetch one row
}
$this->load->view('your_editpage.php',$data);
}