我希望使用隐藏列更新一行,与我的ID相比较。我将我的id放入并将我的哈希存储到表中。我想做一些类似的更新表设置行,其中md5(id)=哈希然后更新..我到目前为止得到了这个。我该如何解决?
控制器
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 updateProduct($data){
$this->db->update('storelte_articulos',$data);
$this->db->where('md5(id)',$this->input->post('id'));
}
数据表
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{
}
}
});