[WTA] Multiple select form handling

Discussion in 'PHP' started by junandya, Oct 19, 2007.

  1. #1
    Hello,

    I'm newbie in programming, i have some code like this:

    <FORM method="post" action="">
    <SELECT multiple name="segment[]">
    <OPTION value="1">Building & Industry</OPTION>
    <OPTION value="2">Mechanical & Electrical</OPTION>
    <OPTION value="3">Civil</OPTION>
    <OPTION value="4">Oil & Gas</OPTION>
    <OPTION value="5">Water Sanitation</OPTION>
    <OPTION value="6">Dredging</OPTION>
    <OPTION value="7">Tunnel</OPTION>
    </SELECT>
    <INPUT type="submit" value="submit">
    </FORM>



    <?PHP
    $listvals=$_POST[segment];
    $n=count($listvals);
    echo "User chose $n items from the list.<br>\n";

    for($i=0;$i<$n;$i++)
    {
    echo $listvals[$i]." ");
    }
    ?>


    And i get the result as an array( assumed i select option 2,3,4,5 ):

    User chose 4 items from the list.
    2 3 4 5


    my big problem is... i need to keep the result as a variable. Let say that the varible we call as $allData, so the final result should be :

    $allData="2 3 4 5";

    i could send this variable to other pages or send it mysql...., how should i do so i could keep the array values to the variable.....

    Please help me
    Best Regards
     
    junandya, Oct 19, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    $allData = implode(' ', (array)$_POST['segment']);
    
    PHP:
     
    nico_swd, Oct 19, 2007 IP
  3. junandya

    junandya Member

    Messages:
    79
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #3
    Thank you very very very much Mr Nico, it's work very well
     
    junandya, Oct 19, 2007 IP