Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Sheffield, UK
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Reading Multiple Select Box values with PHP

    Not sure whether this is an obvious thing i'm missing or what, but here's my prob:

    i'm making a forum search and i need the users to be able to select multiple options, i've built the form and when it is submitted the querystring looks lke this:

    query=search+terms&type=AND&case=1&forums=0001&forums=0025&forums=0027&field=post&submit=Search

    which is good, only problem is, when i dump the contents of $_GET, i get this:

    array(7) { ["query"]=> string(12) "search terms" ["type"]=> string(3) "AND" ["case"]=> string(1) "1" ["forums"]=> string(4) "0027" ["field"]=> string(4) "post" ["submit"]=> string(6) "Search" }

    As you can see, i only get the last value for the forum ID, any ideas on how to get all the other ones as well?
    "To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

    (Me Me Me Me Me Me Me Me Me)

  • #2
    New Coder
    Join Date
    May 2003
    Location
    UK
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    forums = forums

    You cant give 3 values to forums variable and expect the progrem to remember them all.

    You need forums1, forums2, forums3, etc then all of them will be stored.
    They only tell you its a stupid question when they don't know the answer!

  • #3
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    When you have more than one reference to a form value, the latest will overwrite the oldest, so try this.

    <form method="get">

    <select name="forums[]" multiple="multiple">

    <option value="0001">Forum 1</option>
    <option value="0025">Forum 2</option>
    <option value="0027">Forum 2</option>

    </select>

    </form>

    and then an ARRAY of the selected values sould be available through the $_GET['forums'] variable.

    try:

    var_dump($_GET['forums']);

    to check it works.

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Sheffield, UK
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: forums = forums

    Originally posted by michael.hd
    You cant give 3 values to forums variable and expect the progrem to remember them all.

    You need forums1, forums2, forums3, etc then all of them will be stored.
    right then, u seem to be missing the point somewhat, missing-score is right on the money, it hit me the next morning and i dunno why i didn't think of it myslef lol. Ty for the help ppl.
    "To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

    (Me Me Me Me Me Me Me Me Me)


  •  

    Posting Permissions

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