我的查询存在问题。我在这种做法上使用数据表和codeigniter。 我想计算数据,并按发布排序,但我一直计算的数据总是显示[对象对象]。
public function ajax_list_peneliti_perpostingan()
{
$list = $this->post->get_datatables_peneliti_perpostingan();
$data = array();
$no = $_POST['start'];
foreach ($list as $post) {
$no++;
$query = $this->db->query('SELECT count(postedby) FROM peneliti where postedby = "'.$post->postedby.'"');
$row_count = $this->post->count_postedby($post->postedby);
$row = array();
$row[] = $post->postedby;
$row[] = $row_count['0'];
$data[] = $row;
}
$output = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->post->count_all_peneliti_perpostingan(),
"recordsFiltered" => $this->post->count_filtered_peneliti_perpostingan(),
"data" => $data,
);
//output to json format
echo json_encode($output);
}
是我的控制台结果
{"draw":"2","recordsTotal":481,"recordsFiltered":481,"data":[["administrator",{"postedby":"administrator","Total":"1"}],["fadil",{"postedby":"fadil","Total":"25"}],["",{"postedby":"","Total":"1"}],["tilan",{"postedby":"tilan","Total":"160"}],["Editor",{"postedby":"Editor","Total":"2"}],["budi",{"postedby":"budi","Total":"1"}],["admin",{"postedby":"admin","Total":"291"}]]}
答案 0 :(得分:0)
我认为,问题是
$row = array();
$row[] = $post->postedby;
$row[] = $row_count['0'];
$data[] = $row;
你可以改为
$data[] = array(
'postedby'=>$post->postedby,
'total' =>count()
);