猿问

带有多值复选框的 HTML 表单

我在 html 输入表单中有一个复选框字段。在这个值是从另一个表中获取的。我想在这个复选框的帮助下选择多个用户。我的代码有什么问题


<div class="form-group col-md-6">

<label> Supervised BY( At IUAC)<span style="color:red;">*</span></label>

<input type="checkbox" name="user" > <br>

   <checkbox value=""> </checkbox>

<?php 

$sql = "SELECT * from  tblstaff ";

$query = $dbh -> prepare($sql);

$query->execute();

$results=$query->fetchAll(PDO::FETCH_OBJ);

$cnt=1;

if($query->rowCount() > 0)

{

foreach($results as $result)

{               ?>  

<option value="<?php echo htmlentities($result->id);?>"><?php echo htmlentities($result->name);?></option>

 <?php }} ?>

我试过这个代码但它没有显示复选框


慕莱坞森
浏览 240回答 3
3回答

白猪掌柜的

使用输入类型Checkbox字段像这样<?php&nbsp;foreach($results as $result){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;?>&nbsp;&nbsp;<input type="checkbox" name="<?php echo $result->name; ?>" value="<?php echo $result->name; ?>"> <?php echo $result->name; ?> </br>&nbsp;<?php } ?>

桃花长相依

<input type="checkbox">正确代码:<div class="form-group col-md-6"><label> Supervised BY( At IUAC)<span style="color:red;">*</span></label><?php&nbsp;$sql = "SELECT * from&nbsp; tblstaff ";$query = $dbh -> prepare($sql);$query->execute();$results=$query->fetchAll(PDO::FETCH_OBJ);$cnt=1;if($query->rowCount() > 0){foreach($results as $result){?>&nbsp;&nbsp;<input type="checkbox" name="user" value="<?php echo htmlentities($result->id);?>"><?php echo htmlentities($result->name);?><br><?php}}&nbsp; ?>编辑:尝试使用multiple属性<select><?php&nbsp;$sql = "SELECT * from&nbsp; tblstaff ";$query = $dbh -> prepare($sql);$query->execute();$results=$query->fetchAll(PDO::FETCH_OBJ);$cnt=1;if($query->rowCount() > 0){echo "<select name='user' multiple>";foreach($results as $result){?>&nbsp;&nbsp;<option value="<?php echo htmlentities($result->id);?>"><?php echo htmlentities($result->name);?></option><?php}echo "</select>";}?>

德玛西亚99

你可以bootstrap-multiselect像这样使用<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Dropdown Multi Select</title><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" type="text/css" /><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.12/css/bootstrap-multiselect.css" type="text/css" /><script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script><script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.15/js/bootstrap-multiselect.js"></script></head><body><form id="formone"><div style="padding:20px"><select id="chkone" multiple="multiple"><?php&nbsp;$sql = "SELECT * from&nbsp; tblstaff ";$query = $dbh -> prepare($sql);$query->execute();$results=$query->fetchAll(PDO::FETCH_OBJ);$cnt=1;if($query->rowCount() > 0){foreach($results as $result){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;?>&nbsp;&nbsp;<option value="<?php echo htmlentities($result->id);?>"><?php echo htmlentities($result->name);?></option>&nbsp;<?php }} ?></select></div></form></body><script type="text/javascript">$(function() {&nbsp; &nbsp; $('#chkone').multiselect({&nbsp; &nbsp; &nbsp; &nbsp; includeSelectAllOption: true&nbsp; &nbsp; });});</script></html>
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答