PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
chxxangie
Forum Newbie
Posts: 12 Joined: Wed Sep 19, 2007 10:00 pm
Post
by chxxangie » Sat Jan 03, 2009 11:35 pm
Code: Select all
<select name="mentee_list" size="10" multiple="multiple" id="mentee_list">
<?php
$conn = db_connect();
$query = "SELECT * FROM mentormentee where length(username_mentor) = 0 ";
$result = $conn->query($query);
while($row = mysqli_fetch_assoc($result)){ ?>
<option value="<?php echo $row["mentee"]; ?>"><?php echo $row["mentee"]; ?></option>
<?php
} ?>
</select>
how to get the multi value selected by user?
Code: Select all
$mentee_list = $_POST["mentee_list"];
i try this, but it just show the first value only.
i need someone to help me on this plz....thanks in advance...
watson516
Forum Contributor
Posts: 198 Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario
Post
by watson516 » Sun Jan 04, 2009 1:19 am
You just have to add [] after the select name to turn it into an array and then loop through it.
Code: Select all
<form action="action.php" method="post">
<select name="test[]" multiple="multiple">
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
<option value="four">four</option>
<option value="five">five</option>
</select>
<input type="submit" value="Send" />
</form>
Code: Select all
<?php
$test=$_POST['test'];
if ($test){
foreach ($test as $t){echo 'You selected ',$t,'<br />';}
}
?>