Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于数据库PHP未选中复选框_Php_Mysql_Checkbox - Fatal编程技术网

基于数据库PHP未选中复选框

基于数据库PHP未选中复选框,php,mysql,checkbox,Php,Mysql,Checkbox,我试图显示一个复选框,如果存储在数据库中被分配了一个值,我有以下内容,但不确定为什么它不工作,它当前没有选中任何复选框,即使它们已分配了值 $stores = array(); $stmt = DB::query(Database::SELECT, 'SELECT `id`, `store`, `store_name`, `branch_name` FROM `mystores` WHERE `site` = :site ORDER BY `store_name` ASC, `branc

我试图显示一个复选框,如果存储在数据库中被分配了一个值,我有以下内容,但不确定为什么它不工作,它当前没有选中任何复选框,即使它们已分配了值

$stores = array();
    $stmt = DB::query(Database::SELECT, 'SELECT `id`, `store`, `store_name`, `branch_name` FROM `mystores` WHERE `site` = :site ORDER BY `store_name` ASC, `branch_name` ASC');
    $stmt->param(':site', $this->permissions['site'][0]);
    try {
        $result = $stmt->execute()->as_array();
        if (count($result) >= 1) {
            foreach ($result as $row) {
                $checked = in_array($row['store'], $assigns) ? 'checked="checked"' : '';
                $stores[] = '<label><input type="checkbox" name="stores['.$row['store'].']" value="'.$row['store'].'"'.$checked.' />'.$row['store'].' - '.$row['store_name'].' - '.$row['branch_name'].'</label>';
            }
        }
    } catch (Exception $e) {
        FB::error($e);
    }
$stores=array();
$stmt=DB::query(数据库::从'mystores'中选择'SELECT'id','store','store','store\u name','branch\u name','mystores',其中'site`=:site ORDER BY'store\u name`ASC,'branch\u name`ASC');
$stmt->param(':site',$this->permissions['site'][0]);
试一试{
$result=$stmt->execute()->as_array();
如果(计数($result)>=1){
foreach($结果为$行){
$checked=in_数组($row['store'],$assignments)?'checked=“checked”:'';
$stores[]='.$row['store'].-'.$row['store\u name'.-'.$row['branch\u name'.'”;
}
}
}捕获(例外$e){
FB::错误($e);
}

我想你在这里遗漏了一个空格,
“.$checked.”
而且应该是
“.$checked.”
在我放弃任何一种方法之前的两天里,我用头撞了一下数组中的
(至少用三种不同的方式编写)和不同的表。无论我做了什么,我都无法让代码根据数组中的值自动选中复选框

最后,我用jQuery设计了自己的解决方案,效果非常好

如果您感兴趣,请在此处查看:

您是否检查了
$row['store']
$assignments
的内容?其他事情都很好(),检查
$assignments
数组和查询