Page 1 of 1
How to display value in combobox
Posted: Thu Sep 15, 2005 12:40 am
by eshban
Hi,
in database there is a one record stored that is
M-L-XL-XXL
i want to retrieve all these items from database and show it in combo box. MEans i want four values in combobox which are
M
L
XL
XXL
how can i seperate each value and implement it
plz reply
Posted: Thu Sep 15, 2005 12:44 am
by John Cartwright
Code: Select all
//change `table` to your real table name
$result = mysql_query('SELECT * FROM `table`') or die(mysql_error());
//setup the drop down menu
//change input_name to whatever you want it to
echo '<select name="input_name">';
//fill drop down menu
while ($row = mysql_fetch_assoc($result)) {
echo '<option value="'.$row['column_name'].'">'.$row['column_name'].'</a>';
}
//close dropdown
echo '</select>';
edit | oops, misread the question

Posted: Thu Sep 15, 2005 12:50 am
by ryanlwh
if the record is a string M-L-XL-XXL, to separate them:
then use the foreach loop to create the combobox
Code: Select all
<?
echo "<select name='combobox'>";
foreach ($values as $k=>$v)
{
echo "<option value='$v'>$v</option>";
}
echo '</select>';
?>
if the records M,L,XL,XXL, etc, are different columns than use what Jcart gave you.
some problem in combobox
Posted: Thu Sep 15, 2005 1:07 am
by eshban
hi, . i have this string value
"M-L-XL-XXL"
which is stored in db
i want to fetch this record from db and display it in combobox.
i don't want to store this whole string in a combo box.
i want to seperately show each character with in a combox box
means my combo box show four values instead of one which are
M
L
XL
XXL
how can i do this
plz reply
Posted: Thu Sep 15, 2005 3:23 am
by harrisonad
What's wrong with ryanlwh's suggestion? It seems fine to me.