我有这个表包含名称和值,我怎样才能将内容转换成
$row=mysql_fetch_array($result);添加到复选框中?
发布于 2009-01-14 10:34:48
假设$row是一个将列名映射到布尔值1或0的关联数组,您可以这样做:
foreach($row as $colname=>$boolean)
{
//create a name for the checkbox which will produce a nice
//PHP array of checked column names in $_POST['col']
$name="col[$colname]";
//create an id for the checkbox
$id='col'.$colname;
//now we output the checkbox - on form submission you will
//see an element in $_POST['col'][$colname] if checked, and
//no element at all if unchecked...
echo '<input type="checkbox" value="1" '.
'name="'.$name.'" id="'.$id.'" '.
($boolean?'checked="checked"':'').
'>';
//output a label - note we'd tied this to the id of the checkbox
//which means you can click the label to tick the box
echo "<label for=\"$id\">colname</label><br/>";
}当表单提交时,您将在$_POST‘’col‘中获得一个按列名索引的数组,但仅限于选中的那些框,因此您将所有未设置的列设置为false。
发布于 2009-01-14 10:04:42
查看此处:http://dev.w3.org/html5/spec/Overview.html#checkbox-state
所以,试试这个:
<input type="checkbox" checked="true">https://stackoverflow.com/questions/442460
复制相似问题