Php 如何使复选框自动选中?
我想自动选中复选框,我尝试了下面的代码,但它没有选中复选框 HTMLPhp 如何使复选框自动选中?,php,html,Php,Html,我想自动选中复选框,我尝试了下面的代码,但它没有选中复选框 HTML <?php $dbHost = 'localhost'; // usually localhost $dbUsername = 'xxxx'; $dbPassword = 'xxxxxxxxxxx'; $dbDatabase = 'xxxxxxxxxx'; $db = mysql_connect($dbHost, $dbUsername, $dbPassword) or die ("Unable to connect t
<?php
$dbHost = 'localhost'; // usually localhost
$dbUsername = 'xxxx';
$dbPassword = 'xxxxxxxxxxx';
$dbDatabase = 'xxxxxxxxxx';
$db = mysql_connect($dbHost, $dbUsername, $dbPassword) or die ("Unable to connect to Database Server.");
mysql_select_db ($dbDatabase, $db) or die ("Could not select database.");
$variable=$_POST['chk1'];
//print $variable;
$checkbox=implode(',',$variable);
//print $checkbox;
$sql_selectcpnn="SELECT * from clientnetworkpricehistory where id in ($checkbox)";
$querycpnn = mysql_query($sql_selectcpnn);
//print$sql_selectcpnn;
echo "<table style='margin:0px;width:364px'>
<tr>
<th>DateTime</th>
<th>By(employee)</th>
</tr>";
while($row = mysql_fetch_array($querycpnn))
{
$clientid=$row['clientid'];
//print$clientid;
$net=$row['net_id'];
//print$net;
$id=$row['id'];
// print$id;
echo "<tr>";
echo "<td>" .date('d.m.Y H:i', $row['datetime']) . "</td>";
echo "<td>" . $row['user'] . "</td>";
echo"<input type='checkbox' name='chk1[]' value= '$id' checked='checked'/>";
echo "</tr>";
}
echo "</table>";
?>
试试-
echo”“;
您正在使用XHTML,因此需要选中=“checked”echo”代码>?如果这不起作用,您的页面上可能有其他内容,您没有显示给我们,这会阻止复选框被选中。我猜应该是一些JavaScript。(或者您只是查看页面的缓存版本。)checked=“checked”
不是吗。世界上没有浏览器(即使是那些“支持”XHTML的浏览器)关心这个问题。checked=“checked”则不是working@Xavi您的表布局阻止复选框被选中,请删除echo“DateTimeBy(employee)”;它将开始工作
echo "<input type='checkbox' name='chk1[]' checked='checked' value= '$id' />";