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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find selected values from multiple select?

Status
Not open for further replies.

bluedollar

Programmer
Joined
Jul 24, 2003
Messages
174
Location
GB
I have a drop down box that supports multiple selections:

#======================================================================

function dropdownboxmul($SQL,$desc,$name,$form,$id) {
$result = mysql_query($SQL) or die("bad query '$SQL' : ".mysql_error());
echo '<P> '.$desc.' ';
if ($form != &quot;&quot;) {
echo '<SELECT name=&quot;'.$name.'&quot; onChange=&quot;document.'.$form.'.submit();&quot;>';
}
else {
echo '<SELECT name=&quot;'.$name.'&quot; MULTIPLE size=&quot;3&quot;>';
}
while ($res = mysql_fetch_row( $result )) {
foreach($res as $field => $value) {
if ($value == $id) {
echo '<OPTION SELECTED value=&quot;'.$value.'&quot;> '.$value.'';
}
else {
echo '<OPTION value=&quot;'.$value.'&quot;> '.$value.'';
}
}
}
echo '</P></select>';
}

#======================================================================

I use this box in a form and call it as follows:

$this->obconnect->dropdownboxmul($SQL,&quot;&quot;,&quot;paper_id&quot;,&quot;&quot;,''.$result.'');

This works fine, displays on the page and users can make multiple selections. However when the form is submitted, the script that is called, when I do a echo('$paper_id') only the last item selected is displayed. eg.

user selects

3
4
7
8
9

result of echo('$paper_id') = 9

Does anyone know how to display all the items that have been selected?

Any help Would be greatly appreciated.

Thanks

Dan
 
This is an HTML typing issue.
To have the element be an array you need to have the [ignore][][/ignore] after the name:
Code:
echo '<SELECT name=&quot;'.$name.'
[]
Code:
&quot; MULTIPLE size=&quot;3&quot;>';

That will resolve your problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top