I'm creating a data entry system using php/mysql that includes the standard add/update/delete forms in PHP with a MySQL backend.
On the update pages I'm trying to fill the select boxes (that come from other tables) with the values in those other tables, yet defaulting the selection in each of those select boxes to the value currently stored in the main table which is being updated.
For example, the main table is called 'dates' and a related table is called 'department'. So one of the select boxes should have all the various departments listed in the select box but the currently selected value should be whatever is in the department field in the 'dates' table for the record the user is trying to update.
Here's what I currently have for a sample select box code (I'm getting nothing in the select box whatsoever btw):
<select name="department" value="<? echo "$department"; ?>">
$option_block
</select>
The $option_block variable was previously set with the following code:
while ($row = mysql_fetch_array($result7)) {
$department_id = $row['department_id'];
$ddepartment = $row['department'];
$option_block .="<option value=\"$ddepartment\">$ddepartment</option>";
}
Furthermore, $result7 comes from the following code:
$result7 = @($sql7,$connection) or die(mysql_error());
And, $sql7 comes from the following code:
$sql7 = "SELECT department_id, department FROM $table_name3 ORDER BY department";
The department values from the 'dates' table are also set in similar code.
Any help figuring out how to populate my select boxes is appreciated.
Thanks,
S./