显示编辑页面中选中的复选框(PHP)
我想在我的编辑页面上显示选中的复选框此处我的代码此代码显示所有选中的复选框但我只需要显示特定的选中框显示编辑页面中选中的复选框(PHP),php,html,Php,Html,我想在我的编辑页面上显示选中的复选框此处我的代码此代码显示所有选中的复选框但我只需要显示特定的选中框 <?php $id = $_GET['pkcategoryid']; if($id != "") { $updatetenses = mysqli_query($conn, "SELECT * FROM tensecategory WHERE pkcategoryid = '$id'"); $updatetense = mysqli_fetc
<?php
$id = $_GET['pkcategoryid'];
if($id != "")
{
$updatetenses = mysqli_query($conn, "SELECT * FROM tensecategory WHERE pkcategoryid = '$id'");
$updatetense = mysqli_fetch_assoc($updatetenses);
$id = $updatetense['pkcategoryid'];
$cat_name = $updatetense['cat_name'];
$tenid = $updatetense['tenid'];
}?>
<div class="control-group">
<label class="control-label">Category Name :</label>
<div class="controls">
<input type="text" class="span6" name="cat_name" id="cat_name" value="<?php echo $cat_name; ?>" placeholder="Category Name" required />
</div>
</div>
<div class="control-group">
<label class="control-label">Select Tenses </label>
<div class="controls controls-row">
<?php
$tenses = mysqli_query($conn, "SELECT * from tenses");
if(mysqli_num_rows($tenses) > 0)
{
$i = 1;
foreach($tenses as $tens)
{
$pktenseid = $tens["pktenseid"];
$tense_name = $tens["tense_name"];
?>
<div class="span3" style="margin-left:30px;">
<label class="checkbox-inline">
<input type="checkbox" name="tenses" value="<?php echo $tens['pktenseid']; ?>" checked = "<?php echo $tens["tense_name"]; ?>"/> <?php echo $tens['tense_name']; ?>
</label>
在选中的php行中,您必须检查数据库中的数据是否已选中,然后选中该框 最好在数据库中有一个状态列,用于检查或不检查 在您的代码中,因为名称有效且为true,所有复选框均已选中
<input type="checkbox" name="tenses" value="<?php echo $tens['pktenseid']; ?>" <?php if($tens["status"] != 1){echo "checked";} ?>> <?php echo $tens['tense_name']; ?>
它应该是这样的
或
如果要检查特定名称,可以使用此选项
<input type="checkbox" name="tenses" value="<?php echo $tens['pktenseid']; ?>" checked = "<?php if($tens['pktenseid'] == "specific_Name"){echo "checked";} ?>"/> <?php echo $tens['tense_name']; ?>
它显示所有选中的复选框,但我只想指定用户选中的复选框???您想选中一些复选框,对吗?为此,您必须这样编码是的,我使用您的代码,但它显示所有选中的复选框,但我只在第一行选中了3个复选框…在数据库中创建状态列,并且在提交表单后必须选中int类型如果选中,则是否选中。如果选中,则在查询中通过1,否则通过2。不要使用0,1其类型为juggling实际上我不想在表中添加另一列。是否可以使用同一列勾选仅选中选中的复选框???