JSON stands for JavaScript Object Notation is a subset of the object literal notation of JavaScript. Since it can be used in javascript with no muss or fuss. Below is the example of JSON :
var myObject = {nations: [
{name: "England", continent: "Europe"},
{name: "USA", continent: "America"},
{name: "JAPAN", continent: "Asia"}
]
};
This posting will discuss about creating JSON from PHP-Mysql Database driven application. The following is the step to do that :- Get Data from database.
For example we have table "country" contains two columns name, and continent. So, we need to query data.
$query = "select * from country"; $parse = mysql_query($query); while($row = mysql_fetch_object($result)){ $result[] = $row; } - Convert data to json
- Create json object
- Check JSON
That's it. JSON already created
var myString = '<?php json_encode($result);?>';
var myObject = eval('(' + myString + ')');
No comments:
Post a Comment