views:

245

answers:

2

hi ,

in this code how can selected multiple value from dropdown list

<?php 


include ("connect.php");

$member_id = intval($_POST['sector_list']); 


if($member_id == 0) { 
    // Default choice was selected 
} 
else { 
    $res = mysql_query("SELECT * FROM members WHERE MemberID = $member_id LIMIT 1"); 
    if(mysql_num_rows($res) == 0) { 
        // Not a valid member 
    } 
    else { 
        // The member is in the database 
    } 
} 
?> 

<form method="post" action=""> 
    <input type="hidden" name="sector" value="sector_list">  
    <select name="sector_list" class="inputstandard" multiple="multiple">  
        <option value="0">send to</option> 
        <?php  
        $result = mysql_query('SELECT * from members') or die(mysql_error());   

        while ($row = mysql_fetch_assoc($result)) { 
            echo '<option value="' . $row['MemberID'] . '">' . $row['MemberName']. '</option>';  
        } 
        ?>  
    </select> 
</form> 

assume the drop down list contain on (a,s,d,f,g,h,j,)

users selects multiple value ( a,s,j)

output = a,s,j not only j

???

+2  A: 

(PHP Manual explanation)

Change the list's name to be an array (have [] at the end):

<select name="sector_list[]" class="inputstandard" multiple="multiple">

$_POST['sector_list'] will be an array of all the chosen options

Michael Mrozek
A: 

Change name of the select to:

<select name="sector_list[]" class="inputstandard" multiple="multiple">  

In your code you can get them like:

print_r($_POST['sector_list']);
Sarfraz
Thank you for all the problem is solved
sandy