我尝试了另一个问题的答案,但我真的不知道如何解决我的代码。...请帮助解决此问题。
我想显示从mysql数据库到datatables的数据,当我显示所有数据时,它的工作确实很好,但是当我使用where子句时,它显示500个内部服务器错误。
这是我的观点
<div class="card-body">
<div class="table-responsive">
<table id="orgAkt_data" class="table table-striped table-hover">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Place</th>
<th>Category</th>
</tr>
</thead>
</table>
</div>
</div>
<script>
$(document).ready(function(){
var dataTable = $('#okas_data').DataTable({
"processing":true,
"serverSide":true,
"order":[],
"ajax":{
url:"<?php echo base_url() . 'PruCtrl/fetch_okastable'; ?>",
type:"POST"
},
"columnDefs":[{
"orderable":false,
},
],
});
</script>
这是我的控制器
function fetch_okastable(){
$id_p = $this->session->userdata("id_p");
$load_data = $this->Pru_model->make_okas_tables($id_p);
$data = array();
$no = 1;
foreach($load_data as $row){
$sub_array[] = $no++;
$sub_array[] = $row->name;
$sub_array[] = $row->place;
$sub_array[] = $row->category;
$sub_array[] = '<button type="button" name="update" id="'.$row->id.'" class="btn btn-warning btn-xs">Update</button>';
$sub_array[] = '<button type="button" name="delete" id="'.$row->id.'" class="btn btn-danger btn-xs delete"> <i class="fa fa-trash"></i></button>';
$data[] = $sub_array;
}
$output = array(
"draw" => intval($_POST["draw"]),
"recordsTotal" => $this->Pru_model->get_all_data(),
"recordsFiltered" => $this->Pru_model->get_filtered_org(),
"data" => $data
);
echo json_encode($output);
}
这是我的ci模型
var $okas_table = "okas_table";
var $select_column = array("id","id_p","name","place","category","img");
var $order_column = array(null,"id_p","name","place","category",null);
function make_query_okas($id_p){
$this->db->select($this->select_column);
$this->db->from($this->org_akt_table);
$this->db->where("id_p",$id_p);
if(isset($_POST["search"]["value"]))
{
$this->db->like("id",$_POST["search"]["value"]);
$this->db->or_like("name", $_POST["search"]["value"]);
$this->db->or_like("place", $_POST["search"]["value"]);
$this->db->or_like("category", $_POST["search"]["value"]);
}
if(isset($_POST["order"]))
{
$this->db->order_by($this->order_column[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
}
else
{
$this->db->order_by('id', 'DESC');
}
}
function make_okas_tables($nim){
$this->make_query_okas($nim);
if($_POST["length"] != -1)
{
$this->db->limit($_POST['length'], $_POST['start']);
}
$query = $this->db->get();
return $query->result();
}
function get_filtered_okas(){
$this->make_query_okas();
$query = $this->db->get();
return $query->num_rows();
}
function get_all_data(){
$this->db->select("*");
$this->db->from($this->okas_table);
return $this->db->count_all_results();
}