如果它等于然后更新,我如何将我的id与我的哈希id进行比较?问题是,当我想要更新任何行不适当时,因为没有检测到我的隐藏输入并在任何行上更新相同的东西?我该怎么解决?这是我到目前为止所得到的。我正在使用datatables jquery和codeigniter
http://alasksoft.tk/login
凭据管理员 - 管理员
当我想在我的php控制器中访问此输入return '<input type="hidden" name="id" value="'+data+'" >';
时,我无法看到因为我没有在厄运中,因为datatables jquery正在隐藏它如何在不显示它的情况下修复它?
更新控制器
public function updateProduct(){
$descripcion = $this->input->post('description');
$cost_price = $this->input->post('cost_price');
$selling_price = $this->input->post('selling_price');
$wprice = $this->input->post('wprice');
$min_stock = $this->input->post('min_stock');
$stock = $this->input->post('stock');
$max_stock = $this->input->post('max_stock');
$data = array(
'descripcion' => $descripcion,
'precio_compra' => $cost_price,
'precio_venta' => $selling_price,
'precio_mayoreo' => $wprice,
'existencia_minima' => $min_stock,
'existencia' => $stock,
'existencia_maxima' => $max_stock
);
if ($data['existencia'] > $data['existencia_minima']) {
$this->json(array('min_stock' => 'el stock no puede ser mayor al min'));
}elseif ($data['existencia_maxima'] < $data['existencia']) {
$this->json(array('max_stock' => 'el stock no puede ser mayor al max'));
}else{
$this->products->updateProduct($data);
$this->json(array('msg' => 'successfully added'));
$this->json($data);
}
}
更新模型
public function isExistsProduct($data){
$this->db->select('descripcion');
$this->db->from('storelte_articulos');
$this->db->where('descripcion',$data['descripcion']);
$query = $this->db->get();
return $query->num_rows() == 0 ? false : true;
}
public function updateProduct($data) {
$this->db->update('storelte_articulos',$data);
$this->db->where('md5(id)',hash('md5', $this->input->post('id')));
}
ajax表
var table = $('#example').DataTable({
"lengthChange": false,
responsive: true,
dom: 'Blfrtip',
buttons: [{
extend: 'excelHtml5',
exportOptions:{
columns: [1,2,3,4,5,6]
}
},{
extend: 'csvHtml5',
exportOptions:{
columns: [1,2,3,4,5,6]
}
},{
extend: 'pdf',
exportOptions: {
columns: [1,2,3,4,5,6]
}
}],
ajax: {
url: URL_GET_DATATABLE,
type: 'POST',
},
columnDefs:[{
targets: -1,
data: null,
defaultContent: "<a href='#'><span class='glyphicon glyphicon-pencil'></span></a>"
},{
targets: 7,
render: function (data) {
return (data == 1) ? "<span class='label label-success'>active</span>":"<span class='label label-danger'>inactive</span>";
}
},
{
targets: 0,
visible: false,
render: function (data) {
return '<input type="hidden" name="id" value="'+data+'" >';
}
}],
fnRowCallback: function (data,nRow) {
if (nRow[7] == 0) {
$(data).css({'background-color':'#f2dede'});
}else if(nRow[7] == 1){
$(data).css({'background-color':'#dff0d8'});
}else{
}
}
});
答案 0 :(得分:0)
实际上很难理解你的问题但我能从我的经验中得出的是这行代码
public function updateProduct($data) {
$this->db->update('storelte_articulos',$data);
$this->db->where('md5(id)',hash('md5', $this->input->post('id')));
}
您首先更新表而不是使用where,因此将其更改为
public function updateProduct($data) {
$this->db->where('md5(id)',hash('md5', $this->input->post('id')));
$this->db->update('storelte_articulos',$data);
}