SRL Archive - General

Generating a dropdown list in PHP?


jimthesoundman

2010-02-23 01:39:00

I've got an array in my SQL database. Each record has three fields.
I'm running a query and assigning the data to an array called $itemsarray.
Field one is the primary key, INT 10, auto increment.
Field two is the item_name, VARCHAR 50.
Field three is the item_number, which is like an inventory number, INT 10.

I would like to generate a dropdown list with field two, and whichever one is selected, pass field three on to the next page.

I'm trying this code but it doesn't work:
function generateSelect($name = '', $options = array(id, item_name, item_number))
{
$html = '<select name="'.$name.'">';
foreach ($options as $option => $value)//
{
$html .= '<option value='.$value.'>'.$option[item_name].'</option>';
}
$html .= '</select>';
return $html;
}

I'm calling that function with this line:
$dropdownlist=generateSelect('Item List', $itemsarray);
echo $dropdownlist;

My brain is fried and I can't figure out what I'm doing wrong.

Thanks in advance,

JIM

Frement

2010-02-23 01:46:41

How does it not work?

EDIT: Anyways, i fixed it up a little for you.
http://www.frement.net/srl/jim.php