How to display value in combobox

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

Post Reply
eshban
Forum Contributor
Posts: 184
Joined: Mon Sep 05, 2005 1:38 am

How to display value in combobox

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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 :(
Last edited by John Cartwright on Thu Sep 15, 2005 11:52 am, edited 1 time in total.
ryanlwh
Forum Commoner
Posts: 84
Joined: Wed Sep 14, 2005 1:29 pm

Post by ryanlwh »

if the record is a string M-L-XL-XXL, to separate them:

Code: Select all

$values = explode('-',$record);
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.
eshban
Forum Contributor
Posts: 184
Joined: Mon Sep 05, 2005 1:38 am

some problem in combobox

Post 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
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post by harrisonad »

What's wrong with ryanlwh's suggestion? It seems fine to me.
Post Reply