Take the 2-minute tour ×

I want to write a PHP API through I can create JSON file by using MySQL.

Suppose I have a table "A" and I have 2 columns FILENAME and FILETYPE with 10 rows inserted.

I have to write a PHP code which will create a JSON file and take the data from table A (i.e. 10 rows) and print the value in a valid JSON format into JSON file.

share|improve this question
please turn off caps lock while typing –  NullPoiиteя Dec 3 '12 at 9:52
show us wat u have tried?? –  bipen Dec 3 '12 at 9:53
the question format is just bad. You aren't showing any code, you are asking for the ppl here to do all the work for you... take a look at the json_encode() function –  Naryl Dec 3 '12 at 9:54
ARE MAD WHILE TYPING YOUR QUESTION? –  John Woo Dec 3 '12 at 9:54
sorry for the caps lock, i have no idea how to start with it. i have created a media player by using html5, jquery and json. The json entry is done by user. now i want to take the values from the mysql using php –  user1872169 Dec 3 '12 at 9:58
add comment

1 Answer

Just select the data, and then do:


read the docs to see what the output will be.
If you need some more bells and whistles, there is a Zend_Json object, among others (just google for "PHP JSON class"), and have a look at the results

share|improve this answer
thank you very much for your help. Hope this will be helpful for me. –  user1872169 Dec 3 '12 at 10:02
If the data has to be sent to the client, don't write it to a file BTW, just echo the json string: echo json_encode($theData);, and it'll be sent as the response to your AJAX call. –  Elias Van Ootegem Dec 3 '12 at 10:05
can you suggest me some link then it will be very helpful for me. thank you in advance. –  user1872169 Dec 3 '12 at 10:06
Well, apart from the 2 links I already supplied, here's a link to an example using jQuery, PHP and JSON encoded data, just google PHP Json AJAX jQuery tutorials or something, it honestly isn't that hard –  Elias Van Ootegem Dec 3 '12 at 10:09
add comment

Your Answer


