Results 1 to 5 of 5

Thread: PHP retriving all selected items from a SELECT

  1. #1

    Thread Starter
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    PHP retriving all selected items from a SELECT

    using the multiple attribute on the select box

    with ASP you can do this and it returns ALL selected values


    Code:
    <%@ Language=VBScript %>
    <HTML><HEAD>
    </HEAD>
    <BODY>
    <%
    Dim s
    s=request("fooditems")
    response.write(s)
    
    %>
    <form actiopn=m.asp>
    <select name='fooditems' size='4' multiple>
    <Option value=1>option1</option>
    <Option value=2>option2</option>
    <Option value=3>option3</option>
    <Option value=4>option4</option>
    <Option value=5>option5</option>
    <Option value=6>option6</option>
    <Option value=7>option7</option>
    <Option value=8>option8</option>
    <Option value=9>option9</option>
    </select>
    <input type='submit'>
    </form>
    </BODY></HTML>
    How do I do the same in PHP?

    Thanks
    Mark
    -------------------

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    From the PHP manual:
    Code:
    PHP also understands arrays in the context of form variables, but only in one dimension. You may, for example, group related variables together, or use this feature to retrieve values from a multiple select input:
    
    Example 7-2. More complex form variables
    
    <form action="array.php" method="post">
        Name: <input type="text" name="personal[name]"><br>
        Email: <input type="text" name="personal[email]"><br>
        Beer: <br>
        <select multiple name="beer[]">
            <option value="warthog">Warthog
            <option value="guinness">Guinness
            <option value="stuttgarter">Stuttgarter Schwabenbräu
            </select>
        <input type="submit">
    </form>
    Note the name[] syntax
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    Thanks parksie

    I was asking on behalf of a friend so I'll pass it on.
    Mark
    -------------------

  4. #4

    Thread Starter
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    parksie

    Here's the reply I got when I emailed my friend a link to this page so I though I'd better pass it on:


    Thanks dude, bloody obvious when you think about it!! Doh!! Couldn't find
    that anywhere!!

    You are a god!!!

    Me! I'm the god parksie, not you
    Mark
    -------------------

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I'm a bigger god than you
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width