Collecting choices from several selection boxes and storing them

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nt9

    Collecting choices from several selection boxes and storing them

    I am very new with php so excuse me please if the question seems really
    easy.I have a page(form) which displays a list of the titles of some
    books(retreived from a database) and each title has a selection box with
    option values 1 to 7 each.The user should be able to enter 7 choices of his
    favourite books and store them in the database at a table called preferences
    with fields: customer_id ,first_choice, sec_choice,thir d_choice etc.I am
    really stuck in implementing how I can collect the choices and link them
    with each book's code so that i can store them in the table.I would really
    apreciated if somebody could give me at least a hint.
    Thank you


  • Alvaro G. Vicario

    #2
    Re: Collecting choices from several selection boxes and storing them

    *** nt9 escribió/wrote (Tue, 31 Aug 2004 18:59:40 +0100):[color=blue]
    > I am very new with php so excuse me please if the question seems really
    > easy.I have a page(form) which displays a list of the titles of some
    > books(retreived from a database) and each title has a selection box with
    > option values 1 to 7 each.The user should be able to enter 7 choices of his
    > favourite books and store them in the database at a table called preferences
    > with fields: customer_id ,first_choice, sec_choice,thir d_choice etc.I am
    > really stuck in implementing how I can collect the choices and link them
    > with each book's code so that i can store them in the table.[/color]

    PHP allows you to treat form fields as arrays if you give them the
    appropiate name. I particularly love arrays. In your case it could be
    something like:

    <select name="book[1244][]" multiple>
    <option value="foo">Foo blah blah</option>
    <option value="bar">Bar bleh bleh</option>
    ....
    </select>

    where 1245 is the book ID in database. Then in your script you'll have as
    may arrays as books, each one containing as many elements (arrays) as
    selected options:

    $_POST['1245'][0] --> 'foo'
    $_POST['1245'][1] --> 'bar'
    ....




    --
    --
    -+ Álvaro G. Vicario - Burgos, Spain - ICQ 46788716
    +- http://www.demogracia.com (la web de humor para mayores de 100 años)
    ++ «Sonríe, que te vamos a hacer una foto para la esquela»
    --

    Comment

    Working...