I have a PHP form that shows data from a MySQL table. Each row obviously has different data, what I want to do is have a drop down list that displays data relevant to the data entry in each row.
for example, lets say I have two tables. Fruit and Fruit_Colors, as below:

so if my PHP Form was displayed as below, the MySQL data named fruits would display the data in the Fruit column. The color would then be fetched from the Fruit_Colors table depending on the PHP form output value in field 'Fruit'. so the drop down list for each row will be different.

my PHP form table syntax is:
<table id="hor-minimalist-a">
<tr>
<th>ID</th>
<th>Fruit</th>
<th>Color</th>
</tr>
<? while($row = $fruits->fetch(PDO::FETCH_ASSOC)) { ?>
<tr>
<td><? echo $row['id']; ?></td>
<td><? echo $row['fruit']; ?></td>
<td><SELECT NAME="fruitcolor" id="fruitcolor">
<OPTION VALUE=0 >
*// what goes here???*
</option>
</SELECT>
</td>
</tr>
<? } ?>
</table>
Any advice how I can complete this would be appreciated. remember this table could be up to 50 rows so need a dynamic way of passing the 'fruit' value to the drop down list.
Syntax I know for the drop down list populations is:
function fruitcolor_dropdown($db)
{
$result = $db->query("select color from Fruit_Color where Fruit=*'outputted value'*");
return $result;
}
$colors= fruitcolor_dropdown($db);
while($row = $colors->fetch(PDO::FETCH_ASSOC)) {
$color=$row["color"];
$optionsfruitcolors.="<OPTION VALUE=\"$color\">".$color;
}
Advice appreciated as always. Thanks and Regards.
fruit_colortable usingfruitIDinstead offruit_nameas the linking field. You should also have a unique ID field on this table, otherwise it would be impossible to delete a record or correct a spelling (eg you haveYellobananas in the table, but how would you fix that without a reference ID?)