I’m using JSON_encode to send data to a js file for tracks. A user could have one or several tracks so that’s where the problem lies. Not sure how to organise my array to allow for several arrays. I can’t use an array within an array since all the JSON data needs to be separated preferably so there will be something like;
track1 {ID:110232....}
track2 {ID:21402....}
What I have now works fine if there is just one track.
$ID = $_GET['ID'];
$result = mysql_query("SELECT * FROM tracks WHERE ID = '$ID' ORDER BY timestamp DESC");
while($row = mysql_fetch_array($result)){
$T_ID = $row['T_ID'];
$T_url = $row['url'];
$T_name = $row['name'];
$T_timestamp = $row['timestamp'];
$arr = array('T_ID' => $ID,'T_name' => $T_name, 'T_url' => $T_url, 'T_timestamp' => $T_timestamp );
echo json_encode($arr);
}
Why can’t you use an (associative) array inside an container array like this:
This results in a JSON structure like this, which keeps all your tracks in separate objects:
As noted in the comments you should switch to PDO or mysqli- functions, but this doesn’t matter for the problem at hand..