I am looking for any advice on how to do this, the concept is confusing me. I am not looking for an exact solution, just help with the logic.
I have a HTML form that is like this:
| Name | Price | Comment
Which I then pass to PHP script that updates this as a record inside the database. The problem being is that, I am going going to be creating multiple entries (through JQuery) and I don't know how to pass these as one through to the PHP file. I know that I can do this:
<input type="name" id="name[]" value="" />
And handle each of the posts as an array, and, I can do this for all of the fields inside the form. But is there an efficient way to link them all up?
For example:
If I have 5 new rows then the array is going to be:
$_POST['names'] = {"name1", "name2", "name3", ...}
$_POST['cost'] = {"cost1", "cost2", "cost3", ...}
$_POST['comments'] = {"comment1", "comment2", "comment3", ...}
I hope that this makes sense and someone can help me!
This can actually be done with HTML alone, and all your values will be structured even better than you suggest.
<form>
<div class="row">
<input name="rows[0][name]"/>
<input name="rows[0][price]"/>
<input name="rows[0][comment]"/>
</div>
<div class="row">
<input name="rows[1][name]"/>
<input name="rows[1][price]"/>
<input name="rows[1][comment]"/>
</div>
</form>
Then in PHP access $_REQUEST['rows']
and see its contents.