..


Sponsored Links

How do I convert a MySQL query results in a JSON object?

The procedure is quite simple. You run the query, the results are placed in an array that eventually is converted into JSON using the function json_encode ().
Here's an example:






 / / Create an empty array designed to accommodate the query results







 $ Results = array ();









 / / Run the query







 $ Res = mysql_query ("SELECT ...");









 / / Cycle results







 while ($ row = mysql_fetch_assoc ($ res)) {



  



 / / Add to the array ...



  



 $ Results [] = $ row;







 }









 / / Print the results on-screen formatted according to the syntax of JSON

 





 json_encode echo ($ result);



In the same category ...
E-Learning
Linux (Course) Linux (Course)
Complete guide to open-source system. From 49 €.
MySQL (Course) MySQL (Course)
Management of open-source database. From 39 €.
PHP (Course) PHP (Course)
Full course for creating dynamic Web sites. From 49 €.
Sponsored Links