在CI中设计应用程序并遇到了这个奇怪的问题。 以下是模态
public function _get_datatables_query()
{
$sql = "select inv2.id,inv1.uniqueid,inv2.pastamount_due, c.name
FROM invoices as inv2
JOIN (SELECT max(id) as maxid, uniqueid from invoices GROUP by uniqueid)
as inv1 on (inv2.id=inv1.maxid and inv2.uniqueid=inv1.uniqueid)
JOIN client as c ON inv2.uniqueid = c.uniqueid";
$query = $this->db->query($sql);
if($query !== false)
{
return $query->result();
}
return NULL; //$query is false. Probably due to bad syntax in the query string
$i = 0;
// var_dump($this->column_search );
foreach ($this->column_search as $item) // loop column
{
if($_POST['search']['value']) // if datatable send POST for search
{
if($i===0) // first loop
{
$this->db->group_start(); // open bracket. query Where with OR clause better with bracket. because maybe can combine with other WHERE with AND.
$this->db->like($item, $_POST['search']['value']);
}
else
{
$this->db->or_like($item, $_POST['search']['value']);
}
if(count($this->column_search) - 1 == $i) //last loop
$this->db->group_end(); //close bracket
}
$i++;
}
if(isset($_POST['order'])) // here order processing
{
$this->db->order_by($this->column_order[$_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)]);
}
}
function get_datatables()
{
$this->_get_datatables_query();
if($_POST['length'] != -1)
$this->db->limit($_POST['length'], $_POST['start']);
$query = $this->db->get();
return $query->result();
}
以下是Controller 公共函数ajax_list() {
$list = $this->client->get_datatables();
$data = array();
$no = $_POST['start'];
foreach ($list as $client) {
$no++;
$row = array();
$client=(array)$client;
$row[] = isset($client['name'])?$client['name']:"---";
$row[] = isset($client['city'])?$client['city']:"---";
$row[] = isset($client['amount_due'])?"Rs.".$client['amount_due']:"Rs.00.00";
$row[] = isset($client['lastdispatch'])?$client['lastdispatch']:"---";
$row[] = isset($client['lastbill'])?$client['lastbill']:"--";
$row[] = isset($client['lastpayment'])?$client['lastpayment']:"---";
}
$output = array(
"draw" => $_POST['draw'],
//"recordsTotal" => $this->person->count_all(),
//"recordsFiltered" => $this->person->count_filtered(),
"recordsTotal" => $this->client->count_all(),
"recordsFiltered" => $this->client->count_filtered(),
"data" => $data,
);
//output to json format
echo json_encode($output);
}
在编译应用程序时,我正在设置错误1096:没有使用表格。选择*限制10.我不知道我哪里出错了,而不是使用get()我返回查询结果。有人请帮忙!
答案 0 :(得分:0)
从函数get_datatables()中删除这些行:
$query = $this->db->get();
return $query->result();
您正在插入数据库,然后使用get()
寻求帮助 Here