I followed this step to find out the data using codeigniter. But I get some error when joining two tables to
use search in datatables. That's my fault,
And then, as I see in the AJAX error documentation , the resolution is to search the search engine in the network browser. And I get 500 Internal Server Error. This I copied the body of the error response.
Error Number: 42000/1064
You have an error in the SQL syntax; check the manual matching> your version of MySQL server for the correct syntax to use next to 'as> nm_propinsiLIKE'% c% 'ESCAPE'! ') ORDER BY id_kotaDESC LIMIT 10' on line 7
SELECT * FROM `kota` as `k` LEFT JOIN `propinsi` as `p` ON `p`.`id_propinsi` = `k`.`id_propinsi` WHERE ( `k`.`id_kota` LIKE '%c%' ESCAPE '!' OR `k`.`nm_kota` LIKE '%c%' ESCAPE '!' OR `p`.`nm_propinsi` as `nm_propinsi` LIKE '%c%' ESCAPE '!' ) ORDER BY `id_kota` DESC LIMIT 10
Error in my request to get list data LIKEfor data.
This is my model for creating a query lookup for datatables,
var $column = array('k.id_kota','k.nm_kota', 'p.nm_propinsi as nm_propinsi');
var $order = array('id_kota' => 'desc');
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();
}
private function _get_datatables_query(){
$this->db->from('kota as k');
$this->db->join('propinsi as p', 'p.id_propinsi = k.id_propinsi');
$i = 0;
foreach ($this->column as $item)
{
if($_POST['search']['value'])
{
if($i===0)
{
$this->db->group_start();
$this->db->like($item, $_POST['search']['value']);
}
else
{
$this->db->or_like($item, $_POST['search']['value']);
}
if(count($this->column) - 1 == $i)
$this->db->group_end();
}
$column[$i] = $item;
$i++;
}
if(isset($_POST['order']))
{
$this->db->order_by($column[$_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)]);
}
}
My function controller to get AJAX JSON,
public function list_kota(){
$this->load->model("kota_model");
$list = $this->kota_model->get_datatables();
$data = array();
$no = $_POST['start'];
foreach ($list as $ko) {
$no++;
$row = array();
$row[] = $ko->id_kota;
$row[] = $ko->nm_kota;
$row[] = $ko->nm_propinsi;
$row[] = '<a class="btn btn-sm btn-primary" href="javascript:void()" title="Edit" onclick="edit_kota('."'".$ko->id_kota."'".')"><i class="glyphicon glyphicon-pencil"></i> Edit</a>
<a class="btn btn-sm btn-danger" href="javascript:void()" title="Hapus" onclick="delete_kota('."'".$ko->id_kota."'".')"><i class="glyphicon glyphicon-trash"></i> Delete</a>';
$data[] = $row;
}
$output = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->kota_model->count_all(),
"recordsFiltered" => $this->kota_model->count_filtered(),
"data" => $data,
);
echo json_encode($output);
}
What should I do now? Any suggestion?