This function will return an HTML select list from two columns in any table.
You have the option of specifying an "other" value wich is useful for null values on
data entry and an "All" option for queries. Also you can specify a default selected
item and a where clause to limit the records in the list.
Feel free to add to this and repost it or comment if you like, it needs some error
handling.
<?
/* Here's three examples of how you can use this function */
/* Simple example */
echo html_drop_down ("formvar1_prod_type"
,"prod_types"
,"prod_type_id"
,"name");
/* An example with an extra value in the list, good for N/A, All values for queries etc.. */
echo html_drop_down ("formvar2_prod_type"
,"prod_types"
,"prod_type_id"
,"name"
,"-1"
,"All Types");
/* An example with a where clause */
echo html_drop_down ("formvar3_prod_type"
,"prod_types"
,"prod_type_id"
,"name"
,"-1"
,"All Types"
,"3"
,"WHERE prod_type_id <> 4");
/* Here's the data used in my example, it should work with any table though:
mysql> select prod_type_id, name from prod_types;
+--------------+-------------------+
| prod_type_id | name |
+--------------+-------------------+
| 1 | Mother Boards |
| 2 | Graphics Cards |
| 3 | Memory |
| 4 | Pointing Devices |
| 5 | Keyboards |
| 6 | Operating Systems |
+--------------+-------------------+
6 rows in set (0.00 sec)