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

Loading comma separated values into combo box in php 1

Status
Not open for further replies.

foxphpbomb

Programmer
Apr 10, 2007
29
US
Say that I have a table row that holds sizes separated by commas: (<? echo mysql_result($result, $num, "itemSize"); ?> would print s, m, l, xl)

how can I load these into separate <option></option> fields?
 
Explode them, and then generate the combo box dynamically.

Code:
$sizes=explode(",",mysql_result($result, $num, "itemSize"));
echo "<select name='mycombobox'>";
foreach ($sizes as $size){

echo "<option value='" . $size ."'>" . $size . "</option>";

}
echo "</select>";



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Code:
$sizes = mysql_result($result, $num, "itemSize");
$_sizes = explode(",", $sizes); //turn into an array
$options = ''; //create holding var
foreach ($_sizes as $size){
 $s = trim($size);
 $options .= "\t<option value=\"$s\">$s</option>\r\n";
}
echo <<<HTML
<select name="selectBox">
$options
</select>

HTML;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top