与';选中';属性在';输入';PHP while循环中的表单标记
我正在使用html表单编辑sql db,因此我希望表单显示数据库中当前的值。我使用while循环来显示所有sql行。我提供了一个简单的单选按钮,允许用户在“列表”(在sql中显示为“0”)或“最近的事务”(在sql中显示为“1”)之间进行选择 单选按钮未预先填充sqlas checked或not中的值与';选中';属性在';输入';PHP while循环中的表单标记,php,forms,input,checked,Php,Forms,Input,Checked,我正在使用html表单编辑sql db,因此我希望表单显示数据库中当前的值。我使用while循环来显示所有sql行。我提供了一个简单的单选按钮,允许用户在“列表”(在sql中显示为“0”)或“最近的事务”(在sql中显示为“1”)之间进行选择 单选按钮未预先填充sqlas checked或not中的值 <form name="edit listing" action="edit_list.php" method="post" id="edit_form" > <ul>
<form name="edit listing" action="edit_list.php" method="post" id="edit_form" >
<ul>
<?php while ($data=mysqli_fetch_assoc($result)):
$transaction = $data['transaction'];
$chkvalue='checked="checked"'; ?>
<li>
<fieldset>
<legend>Designation <h6>Required</h6></legend>
<input name="transaction" type="radio" tabindex="11" value="0" <?php if ($transaction == '0') echo $chkvalue; ?> />
<label for="listings">Listings</label>
<input name="transaction" type="radio" tabindex="12" value="1" <?php if ($transaction == '1') echo $chkvalue; ?> />
<label for="recent_transactions">Recent Transactions</label>
</fieldset>
<input type="submit" formaction="edit_list.php" value="Submit Changes" />
</form>
</li>
<?php endwhile;mysqli_close($con);?>
</ul>
-
指定要求
/>
最近的交易
简短的php插入部分正在运行。我的源代码如下所示:
<input name="transaction" type="radio" tabindex="11" value="0" />
<label for="listings">Listings</label>
<input name="transaction" type="radio" tabindex="12" value="1" checked="checked" />
<label for="recent_transactions">Recent Transactions</label>
列表
最近的交易
但单选按钮不是预填充。
我一整天都在讨论这个问题,这里的任何建议都会非常有帮助,你只需要写
检查而不是check=“checked”
因此,将其更改为:
$chkvalue='checked'; ?>
与此相反:
$chkvalue='checked="checked"'; ?>
您必须只写选中的
而不是check=“checked”
!这不是填充,也不是执行var\u转储($transaction)
并向我们展示您得到了什么,这样我们可以帮助您更好地按原样使用HTML我在默认情况下选中选中的单选按钮没有任何问题。@Crackertastic,我现在看到它必须与我的循环是如何使用设置的有关,单选复选框出现在页面的最后一个单选按钮中,但不是e在此之前,这里来自源代码:最近的交易仍然没有显示在页面上检查。谢谢@Rizer123@rhill45你确定吗?如果我把这个:
复制到一个html文件中,对我来说效果很好!这与我的循环有关,我刚刚注意到它在我的最后一个项目中显示了一个选中的值,但以前没有that@rhill45A.你所列的物品(li)是否超过了尾页标签?应该是吗?