【发布时间】:2017-03-08 03:43:17
【问题描述】:
我的查询有问题。我在这个实践中使用数据表和代码点火器。 我想统计数据,并按postedby排序,但我统计的数据总是显示[object object]。
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"}]]}
【问题讨论】:
-
您是在使用
alert()还是将某些内容与对象连接起来?使用console.log(obj)进行调试。 -
如果您尝试在 HTML 元素/警报消息上输出 ACTUAL 结果,则会出现实际结果。如果您尝试调试结果,则应提取对象:
alert(result.draw) -
也向我们展示脚本
标签: javascript sql codeigniter