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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Please Help, Multi List Selection PHP problem

    Hi

    I am pulling my hair out over this, I have tried many many ways on getting this to work but none have.

    I have a multi list selection box, which the user can select more than one option from. Once submitted this gets sent to a mysql database table.

    Below is my shortened version of the multi list html code:

    <select multiple="multiple" size="10" name="special[]">
    <option value="Abdominal Training"> Abdominal Training </option>
    <option value="Aerobics"> Aerobics </option>
    <option value="Agility"> Agility </option>

    </select>


    If have tried putting [] which creates an array in the mysql table field special, but when I echo it back it just echos 'array'.

    When I try it without the [], and echo it back, it only echos one selection.

    I am still new to php, but have managed to get my head around a lot, but have been stuck on this for weeks, please help.

  • #2
    Regular Coder
    Join Date
    May 2011
    Posts
    242
    Thanks
    1
    Thanked 57 Times in 56 Posts
    Could you post the php code?

  • #3
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,549
    Thanks
    8
    Thanked 1,095 Times in 1,086 Posts
    You are correct, [] makes it an array.

    So, when you process your form, you do it something like this ...

    <?php

    $special=$_POST['special'];
    foreach($special as $myoption){
    echo "myoption: $myoption";
    }


    Use that little snippet to test it out.
    Then within the loop, you'll be saving the data to your database,
    or picking out what you need.

    You might want to also know that in my example above, you can
    look at each individual $section by doing this:
    echo $section[0];
    echo $section[1];
    etc.

    Arrays start at zero (0) for the first item in the array.
    I would use a foreach loop because you won't know how many there are.



    .


  •  

    Posting Permissions

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