Getting multiple selection into one string

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

    Getting multiple selection into one string


    I have a listbox with 5 options.
    I have set it up to be able to choise more than one option.

    What I need to know is how to get all the selection into the one string
    that is stored in the DB

    It is easy to get the first selected option to post into the DB.

    Thanks for your thoughts and aideas.

    Polar ;)


  • Erwin Moller

    #2
    Re: Getting multiple selection into one string

    Polar wrote:
    [color=blue]
    >
    > I have a listbox with 5 options.
    > I have set it up to be able to choise more than one option.
    >
    > What I need to know is how to get all the selection into the one string
    > that is stored in the DB
    >
    > It is easy to get the first selected option to post into the DB.
    >
    > Thanks for your thoughts and aideas.
    >
    > Polar ;)[/color]


    Hi Polar,

    Use arrays.
    Check the following code:

    <html>
    <body>
    Received:
    <br>
    <?
    // empty?
    $mySelection = array();
    if (isset($_POST["mySelectio n"])) {
    $mySelection = $_POST["mySelectio n"];
    }


    foreach ($mySelection as $key => $value) {
    echo $mySelection[$key]."<br>";
    }


    ?>
    <hr>
    make a selection:
    <hr>
    <form action="" method="POST">
    <select name="mySelecti on[]" multiple>
    <option value="green">g reen
    <option value="42">42
    <option value="adams">a dams
    <option value="earth">e arth
    <option value="Zaphod"> Zaphod
    </select>
    <input type="submit" value="send it">
    </form>
    </body>
    </html>

    Regards,
    Erwin Moller

    Comment

    Working...