[英]How to change the value of the database table (Boolean Column which is set as default false) when button is clicked using JQuery or codeigniter
Im using codeigniter datatable where i want to "disable" the specific row when i click delete button (data should not be erased from databse). 我使用codeigniter datatable,当我点击删除按钮时我想“禁用”特定的行(数据不应该从数据库中删除)。
For that i have already set a column in database(column name: deleteflag datatype: boolean default value is false). 为此我已经在数据库中设置了一列(列名:deleteflag数据类型:布尔默认值为false)。
when i change that value from false to true in database, that particular id (tr row will be disabled) which im doing manually in database. 当我在数据库中将该值从false更改为true时,将在数据库中手动执行该特定id(tr行将被禁用)。
i have added a class called $delstatus in delete button and assigned an array ('0'=>' ', '1'=> 'disabled') 我在删除按钮中添加了一个名为$ delstatus的类并分配了一个数组('0'=>'','1'=>'禁用')
All i want is that when i click on delete button that id row should be disabled by changing boolean value from false to true. 我想要的是,当我点击删除按钮时,应该通过将布尔值从false更改为true来禁用id行。
Here is my Controller:
$active_info = array('0'=>'','1'=>'disabled');
foreach ($list as $lists)
{
$delstatus=$active_info[$lists->deleteflag];
$row = array();
$slno++;
$row[] = '<input type="checkbox" class="'.$delstatus.' data-check" value="'.$lists->id.'" onclick="showBottomDelete()"/>';
$row[] = $slno;
$row[] = '<a class="btn '.$delstatus.' btn-sm btn-primary" href="javascript:void(0)" title="Edit" onclick="editCase('."'".$lists->id."'".')"><i class="glyphicon glyphicon-pencil"></i> Edit</a>
<a class="btn '.$delstatus.' btn-sm btn-danger" id="btnDelete" href="javascript:void(0)" title="Delete" onclick="deleteCase('."'".$lists->id."'".')"><i class="glyphicon glyphicon-trash"></i> Delete</a>';
Here is the view for delete in ajax:
function deleteCase(id)
{
if(confirm('Are you sure delete this data?'))
{
// ajax delete data to database
$.ajax({
url : "<?php echo site_url('case/ajax_delete')?>/"+id,
type: "POST",
dataType: "JSON",
success: function(data)
{
//if success reload ajax table
$('#modal_form').modal('hide');
reloadTable();
},
error: function (jqXHR, textStatus, errorThrown)
{
alert('Error deleting data');
}
});
}
}
</script>
Controller for delete:
public function ajax_delete($id)
{
$this->HomeModel->delete_by_id($id);
echo json_encode(array("status" => TRUE));
}
Model for delete:
public function delete_by_id($id)
{
$this->db->where('case_main.id',$id);
$this->db->delete('case_tracker.case_main');
$this->db->where('case_overview.id',$id);
$this->db->delete('case_tracker.case_overview');
}
Note:- case_tracker is my schema name (im using postgre sql) and case_main and case_overview are my table name 注意: - case_tracker是我的模式名称(即使用postgre sql),case_main和case_overview是我的表名
All i want is that when i click on delete button that id row should be disabled by changing boolean value from false to true using codeigniter function or jquery. 我想要的是,当我点击删除按钮时,应该通过使用codeigniter函数或jquery将boolean值从false更改为true来禁用id行。
Please help to processed with code. 请帮助处理代码。
Thanks in advance. 提前致谢。
I Solved my error.. 我解决了我的错误..
Thnx @Shibon for finding my silly (yet a big) mistake. Thnx @Shibon找到了我的愚蠢(但很大)的错误。
Changed my model to: 将我的模型更改为:
public function delete_by_id($id)
{
$this->db->update('table_name',array('deleteflag' => '1'),array('id'=>$id));
if ($this->db->affected_rows())
{
return true;
}
else
{
return false;
}
note:- deleteflag is column name which is used as boolean true or false. 注意: - deleteflag是列名,用作布尔值true或false。 (true for disable the row and false for none)
(对于禁用行为true,对于none禁用false)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.