我有两张桌子,employee
作为父母和license
孩子。他们都有一Lic_ID
列供参考,这一列是PK
inlicense
和FK
in employee
。该license
表还有一个Lic_Type
包含许可证名称的列。
我正在尝试创建一个带有列表框的employee
表格,以便可以更新表格。列表框value
需要填充license.Lic_ID
并且license.Lic_Type
将显示在 中option
。这是我所拥有的:
(Employee name, Id, etc. called out up here)
<?php
echo "<select name=\"Lic\">";
echo "<option value=\"\">Select...</option>";
$sql = $mysqli->query("SELECT Lic_ID, Lic_Type FROM license");
while($row = $result->fetch_assoc())
{
echo "<option value=\"" . $row['Lic_ID'] . "\">" . $row['Lic_Type'] . "</option>";
}
echo "</select>";
?>
这样效果很好,它显示了许可证类型并将值设置为许可证 ID。<option selected="selected">
如果为员工设置了许可证 ID,我想要做的是。这段代码不起作用,但我认为它说明了我正在尝试做的事情:
<?php
echo "<select name=\"Lic\">";
echo "<option value=\"\">Select...</option>";
$sql = $mysqli->query("SELECT license.Lic_ID, license.Lic_Type, employee.Lic_ID FROM employee INNER JOIN license ON employee.Lic_ID = license.Lic_ID");
while($row = $result->fetch_assoc())
{
echo "<option value=\"" . $row['license.Lic_ID'] . "\"";
if($row['employee.Lic_ID'] = $row['license.Lic_ID']){echo "selected=\"selected\";}
echo ">" . $row['license.Lic_Type'] . "</option>";
}
echo "</select>";
?>
有没有办法完成我想做的事情?