I had trouble describing the problem in the title and I'm sure there is something obvious that I'm missing. Lets say that I have 1,000 books in a database and each book has a field called "rating". The default value for "rating" is "not reviewed". If I then create a form where 100 book titles are output on a page and have a form field for the "rating" where the user can select "good" or "bad" for each book from a dropdown box. The user simply goes down the list of 100 books and for each book selects whether the book was good or bad and presses submit at the bottom of the page. The form then is sent for processing. How do I do this to keep the relationship within the form between each individual book and it's rating so that when they get processed the relationship between the book id and the rating is preserved? Do I set the "name" field in the input field for each record to be the book's id and then the value to the selected value for that book? (good/bad) I would then have 100 different name fields on each page and not sure how I would figure out which ones were submitted when using $_POST in the processing script. Or, do I keep the same "name" for each record, and make the value of the select options something I can parse the book id from, like "350-good", "350-bad" and then explode on the - to find the id/value pair that was passed. I'm sure there is something easier. What am I missing?
Set the name of each field to be the book id. then to process, something like: foreach ($_POST as $field) { if (is_numeric($field)) { //process the reply } } PHP:
I suggest this <select name="rating[56]"> <option value="good">good</option> <option value="bad">bad</option> </select> HTML: as a part of form for book with id=56 and in PHP you can access book rating if (is_array($_POST['rating'])) foreach ($_POST['rating'] as $book_id => $rating){ // do whtaever you need with data } PHP: