Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Selects 1

Status
Not open for further replies.

Louth

Programmer
Jan 21, 2004
16
EU
I have the following code for selecting multiple values from a select box. However when I take the $meetings variable it only outputs the last value chosen. How do I gather all the values?

<td width=150><font size=2>Meetings</font></td>
<td><select multiple name=meetings>";

$meeting=mysql_query("select * from db_trainings where title='meetings'");
while ($result=mysql_fetch_array($meeting))
{
$training_name=$result['training_name'];

echo "<option value='$training_name'>$training_name</option>";
}

echo "</td>
 
The trick is using the correct format of name for the SELECT tag.

In order to accept multiple inputs from a SELECT tag, PHP must be expecting an array. If you change:

<select multiple name=meetings>

to

<select multiple name="meetings[]">

Then (assuming this select is in a POST-method form), $_POST['meetings'] will itself be an array with all the selected values in it.

You can use the same technique with checkboxes, too. If you want to get multiple checkbox inputs as an array name all the checkboxes "somename[]".



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top