Jump to content

arrays help needed


doforumda

Recommended Posts

Hi. I want to use json with php. I am getting data from database. now I want to format that in this way

 

{ msg: [{"id":"1"},{"id":"2"},{"id":"3"},{"id":"4"},{"id":"5"}]}

 

to work with it on client side using json.

 

here is my php code

include("db.php");
$query = mysql_query("SELECT * FROM data_table");
$id = "";
while($row = mysql_fetch_assoc($query)){
    $id = $row['id'];
    $JSON_array['msg'] = array();
    $JSON_array['msg']['id'] = $id;
    $JSON_response = json_encode($JSON_array);
    header("Contents: type/json");
    echo $JSON_response;
}

 

help please

Link to comment
https://forums.phpfreaks.com/topic/244114-arrays-help-needed/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.