I’m doing a simple javascript application. It involves several items in different tables stored using MYSQL.
The user has to choose an item from a table. Based on his choice he can choose a second item from another table, then a third item from a third table based on his former choices, and continues on the same pattern.
I just have one simple problem that I don’t know a simple method to import tables from MYSQL into javascript arrays!!
Any ideas of how to do that?!
I find the easiest way to send MySQL data to Javascript using PHP is as a JSON object using jQuery.
In PHP: connect to your db, do your query.
Assuming you store your results in an array called $results, just do:
This will format the output as a JSON object.
This is the javascript side (using jquery) – note the GET var I’m passing as an example, in case you need that for the tablename or id or whatever: