I have a javascript application that’s will keep track of the x&y coordinates of several objects on a ‘canvas.’ I’m planning on storing this data in a 2-dimensional array such as:
new Array(
new Array(id0, x0, y0),
new Array(id1, x1, y1),
new Array(id2, x2, y2));
I want to submit this data to a php script and store it in a mysql database for later retrieval/redisplay. What’s a good way to do this? Should I serialize the array and encode it for transport? I’m using jQuery so if anyone knows of any good functions included in this framework that would be great. Thanks!
Serialize your array to a storable format (usually string), send it to the server that will store it to the DB.
You might use JSON, XML or any other format. I’d go for JSON as it’s less verbose, then using less space in your database.
However be aware that serializing arrays prevent any querying using the database engine. You will have to extract your data, unserialize it, check if it’s the one you need, and rinse and repeat until you found the right array (unless you know the ID of the array you’re looking for).
NB: Don’t forget to use POST request to send it to the server, as GET request have a length limit.