2017-03-08 66 views
0

我的查詢存在一些問題。我在這種做法上使用數據表和codeigniter。 我想統計數據,並通過postedby排序,但我一直計數的數據總是顯示[object object]。數據總是顯示[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"}]]} 
+0

連接一些東西與對象?使用'console.log(obj)'來調試。 – Tushar

+0

如果您試圖在您的HTML元素/警報消息上輸出實際結果,則會發生您的實際結果。如果您嘗試調試結果,則應提取對象: 'alert(result.draw)' – Cyval

+0

向我們顯示腳本 – user4419336

回答

0

我認爲,這個問題是

$row = array(); 
     $row[] = $post->postedby; 
     $row[] = $row_count['0']; 

     $data[] = $row; 

您可以您是否使用'警報()`或更改

$data[] = array(
       'postedby'=>$post->postedby, 
       'total' =>count() 
        ); 
相關問題