Cannot get data from php array to pass to data tables

Cannot get data from php array to pass to data tables

AlexHollingsworthAlexHollingsworth Posts: 5Questions: 3Answers: 0
edited October 2016 in Free community support

Using mysql I am retrieving values from my database and storing the values in an array. Im then using json_encode on the array. I am having trouble passing the data from the array to data tables.

Am I doing this correctly?

          $sql = "SELECT * FROM table";
      $res = mysqli_query($conn, $sql);
      $returnarray = array();
      while($row = mysqli_fetch_assoc($res)) {

    $rowarray = array(      
        "month"=> date('F Y', strtotime("01-".$row['Month'])),
        "cases"=> $row['COUNT(pcnclientreport.casekey)'],
        "pcns"=> $row['SUM(pcnclientreport.tickets)'],
        "total"=> ($row['SUM(pcnclientreport.debt)']),
        "courtfee"=> "£" . ($row['SUM(pcnclientreport.courtissuefee)'],
    );
    $returnarray[] = $rowarray;     
}
mysqli_free_result($res);
return $returnarray;

}

$(document).ready(function() {
var monthlyTable = $('#clientmonthlytable').DataTable({
"ajax": {
"url": "/data.php",
"data": function ( d ) {
d.clientlist = $('#clientlist').val();
}
},

    "columns": [

        {title: "Date<br>(Opened)", data: "month", "iDataSort": 0}, 
        {title: "Cases", data: "cases"},
        {title: "Tickets", data: "pcns"},
        {title: "Debt referred", data: "total"},
        {title: "Court Fees", data: "courtfee"},
        ]

    });

});

$paymentsmonth = paymentsMonthOpen();
echo json_encode($paymentsmonth);
?>

<div class="results_table">
    <table id="clientmonthlytable" class="display" cellspacing="0" width="100%">

    </table>
</div>
This discussion has been closed.