I have got a page with data generated client-side that is formatted as a fifteen column array. The number of rows will vary based on user input, anywhere between 1 and 200 total. I want to pass this array to my server in an efficient manner where it will be inserted into a MySQL database using php, but I don’t know how the data should be packaged for transport. The data in the page is generated using JavaScript and is laid out in this fashion:
<div id="row1" class="row">
<span id="entry1">User generated data.</span>
<span id="entry2">User generated data.</span>
<span id="entry3">User generated data.</span>
...
<span id="entry15">User generated data.</span>
</div>
<div id="row2" class="row">
<span id="entry1">User generated data.</span>
<span id="entry2">User generated data.</span>
<span id="entry3">User generated data.</span>
...
<span id="entry15">User generated data.</span>
</div>
Recommendations anyone?
I don’t think it is canon to repeat the same ID multiple times.
I’d use compound IDs:
At that point you can:
build a POST query with all items as key/values:
entry1_1=User generated data.
…
which will be easily parseable by PHP, or:
build a JSON string in Javascript as a dict of dicts
{ row1: { entry1: “User generate data” }, row2: {…}
you might try to preparse the array for PHP by submitting fields
like this:
entry[1][1]=User generated data.
( “entry[1][1]” is the name of the key. PHP should parse it correctly).
You could also, depending on how you create new items, directly create a POST FORM, appending fields like this to the DOM:
Sorry, but without a better idea of your interaction design, it is awkward to make suggestions.