0

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 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.