我搜索过高低,无法找到我正在寻找的答案。我有一个复选框列表,这些复选框是从数据库中的类别列表动态创建的。现在,我想要做的是能够维护当页面回发给自己时检查哪些复选框,但我正在做的是工作= /
<?php
$mysqli = new mysqli(SERVER_NAME, USERNAME, PASSWORD, DATABASE_NAME);
if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); }
$sql = " SELECT TableID AS WebsiteCategoryID, Category FROM listwebsitecategories ORDER BY Category ASC ";
$stmt = $mysqli->prepare($sql);
$stmt->execute();
$stmt->bind_result($selectWebsiteCategoryID, $selectCategory);
while ($stmt->fetch() == true) :
?>
<div><input type="checkbox" name="websitecategories[]" id="websitecategories<?php echo($selectWebsiteCategoryID); ?>"<?php if (isset($_POST['websitecategories' . $selectWebsiteCategoryID]) == true) echo(' checked="checked"'); ?> value="<?php echo($selectWebsiteCategoryID); ?>" /> <?php echo($selectCategory); ?></div>
<?php
endwhile;
$stmt->close();
?>
我认为这会起作用,但事实并非如此。我仍然可以通过获取一个数组($ websiteCategories = $ _POST ['websitecategories'])来检查哪些复选框,但是在回发上维护它们的检查值是行不通的..请帮忙。