php - Capturing multiple value from dropdown list generated from database

887

I am having problem to capture multiple value from drop-down list which is generated from database.I have to capture multiple value and that also has to be saved in database.Its only capturing the last selected value id insted of all and saving that value to database. here is my code

<?php

    include("config.php");
    $result2 = mysql_query("SELECT Emp, ed FROM pd WHERE manemail = '$mai'");

    echo "<select name='allo' multiple style='width:163px;'>";
    while($row2 = mysql_fetch_array($result2))
    {
        $emp=$row2['Emp'];
        $ed=$row2['ed'];
        echo "<option value='".$ed."' name='" .$ed. "' >" .$emp. " </option>";
    }
    echo "</select>";
?>
40

Answer

Solution:

Add brackets "[ ]" to your select's name:

<select name="allo[]" multiple style='width:163px;'>

Then, you can have all selected values in PHP, like this:

// Here you iterate $_GET['allo'] to get each selected id!
$array_of_ids[] = array();
foreach($_GET['allo'] as $selectedOption)
    $array_of_ids[] = $selectedOption;

print_r($array_of_ids); // This array contains all the selected ids...

People are also looking for solutions to the problem: php - number_format only if not zero

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.