繁体   English   中英

显示下拉列表中的数据,并选择选项进行编辑

[英]Showing data in dropdown list with option selected for editing

我有一个下拉列表,通过从数据库中的表中获取数据来填充。 是否可以在编辑页面上显示相同的下拉列表进行编辑,并选择选项(数据库中存在的值),如果用户更改并选择其他选项,则可以在表格中插入提交此类选项。

我没有尝试任何东西,只要我不知道该怎么做。

<?php
$conn = new mysqli('localhost', 'root', '', '') 
or die ('Cannot connect to db');
$result2 = $conn->query("select id, username, clerkcode, post, case when 
post='Law Clerk' then 1 when post='Law Intern' then 2 else 3 end priority 
from lawclerk order by priority, clerkcode");  
echo "<html>";
echo "<body>";
echo "Clerk Name : &nbsp;&nbsp; &nbsp;";
echo "<select name='search' Id='search' required />";
echo '<option value="">Select Law Clerk/Intern</option>';
while ($row = $result2->fetch_assoc()) {
unset($id, $clerkcode, $username);
$id = $row['id'];
$clerkcode = $row['clerkcode'].' ';
$username = $row['username'];
echo '<option value="'.$clerkcode.'">'.$clerkcode.$username.'</option>';
}
echo "</select>";
echo "</body>";
echo "</html>";
?>

所需的结果:如果用户打开编辑表单,下拉列表将显示数据库中存在的选项以及其中的所有其他选项,以便用户可以根据需要更改它。

您可以在选项标签中检查值。 <option value="'.$clerkcode.'"'; if($clerkcode=="Your value") { echo ' selected '; } echo '>'.$clerkcode.$username.'</option>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM