SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    multi select box

    hi to all
    i need small help in php.
    how to store multi select box values in database.suppose one person prefers 2 or 3 cities in a country.during the normal process last selected value is stored in database.but i want to store all selected values in multiple select box.
    thanks in advance..

  2. #2
    SitePoint Member
    Join Date
    May 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi
    well, can't you store them in one field and separate them with comma ?
    I think this is very easy.
    Free Link Directory : Submit your links now
    PHPTON : My Open Source CMS
    FreeTutos : Free Online Tutorials

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes,i Want Tostore Values Seperated With Comma In A Single Fiels.plz Help Me.

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Hi barnes,
    consider the following code:
    PHP Code:
    <?php
    echo '<pre>';
    print_r($_POST);
    echo 
    '</pre>';

    $imploded implode(","$_POST['multiple_select']);
    echo 
    $imploded;
    ?>

    <form name="test" action="" method="post">
    <select name="multiple_select[]" multiple size="3">
        <option>1</option>
        <option>2</option>
        <option>3</option>
        <option>4</option>
        <option>5</option>
        <option>6</option>
        <option>7</option>
    </select>
    <input name="submit" value="submit" type="submit" />
    </form>
    this gives the output:
    Code:
    Array
    (
        [multiple_select] => Array
            (
                [0] => 4
                [1] => 5
            )
    
        [submit] => submit
    )
    4,5
    The <select> item is turned into an array using the [] brackets so that more than one item can be passed in the suber global $_POST.

    Using that you can then implode() the result into a comma separated string that you can then insert into your database.

    If you need more help, post some code
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

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