gpt4 book ai didi

php - 在 codeigniter 中使用选定的 id 更新一行

转载 作者:行者123 更新时间:2023-11-28 23:38:41 24 4
gpt4 key购买 nike

在我看来,我打印了我表中的所有记录。我通过将其 id 传递给模型来创建一个更新行的按钮。当我打印用于获取 id 的变量时,它被打印出来了。但是当我把它放在查询中时,查询结果是空的。有人可以帮助我吗,我的代码有什么问题?

这是我的 View 代码

echo " <tr><td width='250' name='tanya'>$row->pertanyaan</td>
<td name='jawab'>$row->jawaban</td>
<td width='90'><a href='c_faq/edit?id=".$row->id_faq."' class='btn btn-default' role='button'><i class='glyphicon glyphicon-edit'></i></a>
<button><span class='glyphicon glyphicon-remove'> </span></button></a>
</td>
</tr>";

这是我的 Controller

public function edit()
{
$data["edits"] = $this->m_faq->acts();
$this->load->view('v_editfaq', $data);
}

这是我的模型

public function acts()
{
$idtemp = $this->input->get('id');
$query= $this->db->query('select * from faq where id_faq = "$idtemp"');
return $query->result();
}

当我打印 $idtemp 时,它得到了正确的 id。但是在我将它放入 $query 之后,结果是空的。

最佳答案

row_array 返回单个结果,result_array 返回多个结果,通常用于循环情况。

将查询中的query->result改为query->row

$this->db->select('*');
$this->db->from('faq');
$this->db->where('id_faq',$idtemp);
$result=$this->db->get()->row(); //change result to row
return $result;

同时将 $data["edits"] 中的双引号替换为 Controller 中的 $data['edits']

documentation on- row_array & result_array

关于php - 在 codeigniter 中使用选定的 id 更新一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35005318/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com