: I am trying to make a database driven website about a collecting
: hobby. The problem I am having is how do you design it properly.
: Table A
: companyID, companyName, companyBio
: Table B
: itemID, itemName, colorID, price
: Table C
: colorID, colorName
: How do I design the input and output forms so that instead of having
: to know the companyID and colorID for an item they can select the
: companyName or see the colorName on the query results form?
I like to write a function that takes an array of ID => Name and turns it into a list of <option ...> elements. For example:
$options = array();
foreach ($assoc as $ID => $Name)
$ID = htmlentities($ID); // just to be safe
$Name = htmlentities($Name); // again...
$options = "<option value=\"$ID\">$Name</option>";
/* I join them with a \n for source readability */
return implode("\n", $options);
Now it's just a question of selecting the ID's and names from the database, building them into an assoc array of ID => Name, and passing it to this function. Then wrap the results of the function in a <select ...> and you're good.