select & print multiple value from dropdown list
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['M开发者_如何学PythonemberName']. '</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
???
(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
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']);
精彩评论