Results 1 to 2 of 2

Thread: Generating a dropdown list in PHP?

  1. #1
    Join Date
    Dec 2009
    Posts
    146
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Generating a dropdown list in PHP?

    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:
    Code:
    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:
    Code:
    $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

  2. #2
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    How does it not work?

    EDIT: Anyways, i fixed it up a little for you.
    http://www.frement.net/srl/jim.php
    Last edited by Frement; 02-23-2010 at 07:00 AM.
    There used to be something meaningful here.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •