tags:

views:

24

answers:

1

Can any one give me example or reference for converting mysql database query results in to json object and send it to javascript file then parse the json and display results in javascript file using jquery?

Thanks.

+1  A: 

If you are using PHP, you can use json_encode to convert a PHP array to JSON. Usually mysql results are given in arrays.

Using jQuery, you can give the $.ajax method a dataType of 'json', so it will parse the JSON into a JavaScript array for you. (I'm assuming you are using AJAX.)

Or, you can save load the PHP variable in a JS one by doing this:

var sqlResults = <?=$results?>;

I hope this helps.

Rocket