使用codeigniter删除特定行 [英] Deleting a specific row using codeigniter
本文介绍了使用codeigniter删除特定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
感谢您的所有帮助和建议。这是我对我的问题的回答:
Thank you for all the help and suggestions. Here's my answer to my problem:
查看
<td><a href ="<?php echo site_url('helloworld/delete/'.$row->user_no);?>">delete</a></td>
控制器
function delete($user_no) {
$this->load->model("dbmodel");
$this->dbmodel->delete_row($user_no);
}
模型
model
public function delete_row($id){
$this -> db -> where('user_no', $id);
$this -> db -> delete('users');
redirect('helloworld/');
}
我希望这可以帮助你:)
I hope this can help you :)
我是codeigniter的新用户。我要删除特定的行,但我总是遇到此错误:
I am new in codeigniter. I'm trying to delete a specific row but I always get this error:
404页面未找到
404 Page Not Found
找不到您请求的页面。
这是我的 strong>:
Here is my code in my view:
<td><?php echo anchor('helloworld/delete_row?id='.$row->user_no, 'DELETE', 'id="$row->user_no"'); ?></td>
模型:
function row_delete($id) {
$this->db->where('user_no', $id);
$this->db->delete('users');
}
控制器:
function delete_row(){
$id = $this->input->get('id');
$this->load->model('dbmodel');
$this->dbmodel->row_delete($id);
}
推荐答案
<a href ="<?php echo site_url('controller/delete/'.$row->user_no);?>">delete</a>
or
<?php echo anchor('controller/delete/'.$row->user_no, 'Delete','title="delete"');?>
模型函数: -
public function deleteRecord($table, $where = array()) {
$this->db->where($where);
$res = $this->db->delete($table);
if($res)
return TRUE;
else
return FALSE;
}
控制器: -
public function delete($id = '') {
$this->load->model('dbmodel');
$where = array('user_no' => $id);
$this->dbmodel->deleteRecord('table_name',$where);
}
这篇关于使用codeigniter删除特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文