How do I use the json_encode()
function with MySQL query results? Do I need to iterate through the rows or can I just apply it to the entire results object?
相关问题
- Views base64 encoded blob in HTML with PHP
- Jackson Deserialization not calling deserialize on
- Laravel Option Select - Default Issue
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
as simple as that :-)
I solved like this
How to create JSON using data from MySQL database
JSON (JavaScript Object Notation) is more preferred nowadays over XML as it’s lightweight, readable and easily manageable for exchanging data across various platforms. we’ll see how JSON Data can be created from Employee table stored in MySQL database.
Live : [Example ]
For example $result = mysql_query("SELECT * FROM userprofiles where NAME='TESTUSER' ");
1.) if $result is only one row.
2.) if $result is more than one row. You need to iterate the rows and save it to an array and return a json with array in it.
Code: