所以目前我正在试图弄清楚如何在我下面发布的代码中添加一个下拉菜单。我在互联网上搜索但找不到对我有用的方法,我对编码很新,所以这对我来说很难,其他人可能会觉得这很容易。
<table class="table table-bordered table-striped">
<thead> <!-- add class="thead-inverse" for a dark header -->
<tr>
<th>ID</th>
<th>USERNAME</th>
<th>Crime(s)</th>
<th>Active</th>
<th>EDIT</th>
</tr>
</thead>
<tfoot>
<tr>
</tr>
</div>
</th>
</tfoot>';
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr>
<td>'.$row["id"].'</td>
<td class="username" data-id1="'.$row["id"].'" contenteditable>'.$row["name"].'</td>
<td class="crime" data-id2="'.$row["id"].'" contenteditable>'.$row["crime"].'</td>
<td class="activated" data-id2="'.$row["id"].'" contenteditable>'.$row["activated"].'</td>
<td><button type="button" name="delete_btn" data-id3="'.$row["id"].'" class="btn btn-xs btn-danger btn_delete">DELETE</button></td>
</tr>
';
}
$output .= '
<tr>
<td></td>
<td id="name" contenteditable></td>
<td id="crime" contenteditable></td>
<td id="activated" contenteditable></td>
<td><button type="button" name="btn_add" id="btn_add" class="btn btn-xs btn-success">ADD ACCOUNT</button></td>
</tr>
';
}
else
{
$output .= '<tr>
<td colspan="4">Data not Found</td>
</tr>';
}
$output .= '</table>
</div>';
echo $output;
?>
答案 0 :(得分:0)
由于您提到您要将下拉列表添加到表格的已激活部分,并且该下拉列表应包含Yes
,No
和Being Verified
,因此您可以更新该表列为
<td class="activated" data-id2="'.$row["id"].'" contenteditable>
<select name="activated" id="activated">
<option value="Yes" '.(($row["activated"] == "Yes") ? 'selected="selected"':"").'>Yes</option>
<option value="No" '.(($row["activated"] == "No") ? 'selected="selected"':"").'>No</option>
<option value="Being Verified" '.(($row["activated"] == "Being Verified") ? 'selected="selected"':"").'>Being Verified</option>
</select>
</td>
这将允许在下拉列表中自动选择db $row["activated"]
中的值。