【发布时间】:2019-07-24 03:48:51
【问题描述】:
对不起先生/女士
我正在尝试从 SQL 数据库中检索数据以在数据表中显示特定 ID 的事务数据,但我收到错误消息:Too few arguments to function
说我有
client a
client b
client c
当我单击client a 时,它会检索client a 的所有数据,然后会出现类似
client a 06-07-2019 $500
client a 15-07-2019 $750
client a 22-07-2019 $340
我尝试使用$this->input->get('id'),但当我将id 发送到模型时,它似乎没有检测到它
这是 URL 模式,以及我正在尝试获取的 id
https://dev3.gatra.com/bisdev/bmitra/commission?id=34
这里是调用数据的函数
$(document).ready(function(){
table = $('#commision').DataTable({
"processing": true,
"serverSide": true,
"order": [],
"oLanguage": {
"sSearch": "Search :"
},
"ajax": {
"url": "<?php echo site_url('bmitra/get_dataserverside_commission')?>",
"type": "POST",
"data" : {},
beforeSend:function () {
$("#progressbottom").show();
},
complete:function () {
$("#progressbottom").hide();
$(".tooltip").tooltip("hide");
$('[data-toggle="tooltip"]').tooltip();
}
},
"columnDefs": [
{ "orderable": false, "targets": [5] },
{ "className": "style1", "targets": [ 0,1,2,3,4,5 ] }
],
});
});
这是控制器的代码
function get_dataserverside_commission(){
// $data['commision']=$this->Bmitra_m->_get_datatables_query_commission();
$data = $this->input->get('id');
$list = $this->Bmitra_m->get_datatables_commission($data);
$data = array(
'id' => $data,
);
$no = $_POST['start'];
foreach ($list as $field) {
$option='<center>'
.'<button type="button" title="Hapus" data-toggle="tooltip" data-original-title="Hapus" data-id="'
. $field->id . '" class="btn btn-sm btn-danger" onclick="showpop('.$field->id
.')"><i class="fa fa-trash"></i></button>'
.'</center>';
$row = array();
$row[] = $field->id;
$row[] = $field->company_name;
$row[] = $field->from;
$row[] = $field->to;
$row[] = $field->commission;
$row[] = $option;
// $row[] = '-';
// $row[] = '-';
// $row[] = '-';
// $row[] = '-';
$data[] = $row;
}
$output = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->Bmitra_m->count_all_commission(),
"recordsFiltered" => $this->Bmitra_m->count_filtered_commission(),
"data" => $data,
);
// $this->db->close();
//output dalam format JSON
echo json_encode($output);
}
这是模型的代码
private function _get_datatables_query_commission($id)
{
// $id = $this->input->post('commissionid');
$this->db->select('a.company_name,b.*');
$this->db->from('bis_mitra a');
$this->db->join('bis_set_commission b','a.id = b.bismitra_id','left');
$this->db->where('a.id' , $id);
$this->db->where('a.active', 1);
$this->db->where('a.trash', 0);
$i = 0;
foreach ($this->column_search_commission as $item) // looping awal
{
if($_POST['search']['value']) // jika datatable mengirimkan pencarian dengan metode POST
{
if($i===0) // looping awal
{
$this->db->group_start();
$this->db->like($item, $_POST['search']['value']);
}
else
{
$this->db->or_like($item, $_POST['search']['value']);
}
if(count($this->column_search_commission) - 1 == $i)
$this->db->group_end();
}
$i++;
}
if(isset($_POST['order']))
{
$this->db->order_by($this->column_order_commission[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
}
else if(isset($this->order))
{
$order = $this->order;
$this->db->order_by(key($order), $order[key($order)]);
}
}
// there are 2 function for the model
function get_datatables_commission($id){
$this->_get_datatables_query_commission($id);
if($_POST['length'] != -1)
$this->db->limit($_POST['length'], $_POST['start']);
$query = $this->db->get();
return $query->result();
}
任何帮助和解释将不胜感激
谢谢!
【问题讨论】:
-
您应该在查询字符串中传递 id。请您分享 url 模式,您是如何调用 get_dataserverside_commission 函数的?
-
我已经编辑了问题,先生,请查看
-
请分享showpop功能代码。
-
函数 showpop(id){ $('#id_mitra').val(id); $('#id_mitra2').html(id); $('#delete_modal').modal('show'); } 但它在不同的页面上,我认为那只是为了删除数据
-
不要使用左连接,因为即使在右表中找不到数据,它也会为您提供左表中的所有数据。使用内连接。
标签: javascript sql codeigniter