LaRocca
LaRocca

Reputation: 55

PHP json_encode() returns nothing using dataTables and MWS Theme

what I'm doing wrong here. I'm trying to send the json_encode to a dataTables, using a MWS Themeforest Theme. Here is my ajax code:

<?php
include("../inc/connect.inc.php");

error_reporting(E_ALL);
ini_set('display_errors', 1);

$sql = "SELECT vv.id, vv.licenseplate, vv.emergency, vv.alert, vt.name FROM vehicle_vehicle AS vv 
INNER JOIN client_user_vehicle_map AS cv ON cv.id_vehicle = vv.id
INNER JOIN vehicle_type AS vt ON vt.id = vv.id_type
WHERE cv.id_user = ".$_GET["idUser"];

$rst = mysql_query($sql);
$val = "";
while($lst = mysql_fetch_array($rst)){
    $sql2 = "SELECT id, ignition, date FROM vehicle_tracking WHERE id_vehicle = ".$lst["id"]." ORDER BY date DESC LIMIT 1";
    $rst2 = mysql_query($sql2);
    while($lst2 = mysql_fetch_assoc($rst2)){

        $date = date_create($lst2["date"]);
        $comm  = date_format($date, 'd-m-Y H:i:s');

        if ($lst2["ignition"] == "1"){
            $val = "<center><i class='icol32-bullet-green'></i></center>";
        }else if ($lst2["ignition"] == "0"){
            $val = "<center><i class='icol32-bullet-black'></i></center>";
        }

        $licenseplate = $lst["licenseplate"];
        $data = array($lst["name"], "1", $comm, "1");
        $arr[] = array("name" => $licenseplate, "data" => $data);
    }
}

$output['aaData'][] = $arr;
echo "<pre>";
print_r($output);
echo "</pre>";
echo json_encode($arr); ?>

The result of my print_r is this array:

Array(
[aaData] => Array
    (
        [0] => Array
            (
                [0] => Array
                    (
                        [name] => ITU 2198
                        [data] => Array
                            (
                                [0] => Automóvel
                                [1] => 1
                                [2] => 09-05-2014 19:17:55
                                [3] => 1
                            )

                    )

                [1] => Array
                    (
                        [name] => BANCADA
                        [data] => Array
                            (
                                [0] => Automóvel
                                [1] => 1
                                [2] => 09-04-2014 11:10:51
                                [3] => 1
                            )

                    )

                [2] => Array
                    (
                        [name] => IHC 8764
                        [data] => Array
                            (
                                [0] => Automóvel
                                [1] => 1
                                [2] => 09-05-2014 19:22:14
                                [3] => 1
                            )

                    )

                [3] => Array
                    (
                        [name] => IFT 0003
                        [data] => Array
                            (
                                [0] => ISCA
                                [1] => 1
                                [2] => 07-05-2014 15:30:13
                                [3] => 1
                            )

                    )

                [4] => Array
                    (
                        [name] => IFT 0004
                        [data] => Array
                            (
                                [0] => ISCA
                                [1] => 1
                                [2] => 07-05-2014 13:20:37
                                [3] => 1
                            )

                    )

            )

    ))

But my json_encode is blank. Can you help me with this? Thanks a lot.

Upvotes: 1

Views: 480

Answers (1)

Shakeel Ahmed
Shakeel Ahmed

Reputation: 1858

Add this line after while(....

$lst2 = array_map('utf8_encode', $lst2);

This will convert all the elements into utf8.

Upvotes: 1

Related Questions