how to retrieving data from mysql and output json php? : <p>i Have this code to retrieving data from mysql and output json from php</p>

<pre><code>&lt;?php
header("Access-Control-Allow-Origin: *");
header('Content-Type: text/html; charset=utf-8');
include 'system/config.php';
$db=mysql_connect($DB_HOST, $DB_USER, $DB_PASS) or die('Could not connect');
mysql_select_db($DB_NAME, $db) or die('');

$result = mysql_query("SELECT * from users") or die('Could not query');

if(mysql_num_rows($result)){
    echo '{"Data":[';

    $first = true;
    $row=mysql_fetch_assoc($result);
    while($row=mysql_fetch_row($result)){
        //  cast results to specific data types

        if($first) {
            $first = false;
        } else {
            echo ',';
        }
        echo json_encode($row);
    }
    echo ']}';
} else {
    echo '[]';
}

mysql_close($db);

?&gt;
</code></pre>

<p>What i need to do exactly like that to split every user with new data line</p>

<pre><code>        {
        "data":[ {
            "user_id":"1",
            "user_name":"ahmed",
            "user_rank":"admin",
            "color":"blue",
            "user_avatar":"default_avatar.png",
            "user_age":"30",
            "user_email":"root@root.com",
            "trending_datetime":"0000-00-00 00:00:00",
        },
        "data":[ {
            "user_id":"2",
            "user_name":"ahmed2",
            "user_rank":"user",
            "color":"green",
            "user_avatar":"default_avatar.png",
            "user_age":"40",
            "user_email":"ahmed2@root.com",
            "trending_datetime":"0000-00-00 00:00:00",
        }
    }
</code></pre>

<p>But is showing like that and i know there is something missing..am still learning</p>

<pre><code>
{
    "Data": [["5", "lucifer", "user5_37994384.png"], ["7", "Ahmed", "default_avatar.png"], ["10", "Viona", "default_avatar.png"], ["11", "Dream", "default_avatar.png"], ["12", "Zanos", "default_avatar.png"], ["13", "Dean.Winchester", "default_avatar.png"], ["19", "sama", "default_avatar.png"], ["33", "demo", "default_avatar.png"], ["34", "super", "default_avatar.png"], ["42", "tazooo", "default_avatar.png"], ["44", "devil", "default_avatar.png"]]
}
</code></pre>

<p>Thanks for help</p>
