foreach循环中的checkbox值获取不工作

ulydmbyx  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(353)

使用下面给定的代码,我试图从mysql数据库中获取复选框的数据,该数据库不起作用,只获取最后一个选中的值。
var_dump($checked); 它给出了正确的结果。
php脚本

$group_id = $_POST['group_id'];
$team_id = $_POST['team_id'];
if(!empty($_POST['team_id'])) {
        foreach($_POST['team_id'] as $checked) {
            // var_dump($checked);
                $sql = $db->prepare("SELECT a.team, a.player, a.result, a.note, b.category FROM teams a INNER JOIN  groups b ON a.team_id = b.id WHERE a.team_id = :team_id_id AND a.group_id = :group_id ");
                $sql->execute(array(':team_id' => $checked, ':group_id' => $group_id));
        }
        while($row = $sql->fetch(PDO::FETCH_ASSOC) ) {
            $row1[] = $row;
        }

}
hc2pp10m

hc2pp10m1#

使用while循环 foreach loop 因为这会引起身份问题

$group_id = $_POST['group_id'];
$team_id = $_POST['team_id'];
if(!empty($_POST['team_id'])) {
    foreach($_POST['team_id'] as $checked) {
            $sql = $db->prepare("SELECT a.team, a.player, a.result, a.note, b.category FROM teams a INNER JOIN  groups b ON a.team_id = b.id WHERE a.team_id = :team_id_id AND a.group_id = :group_id ");
            $sql->execute(array(':team_id' => $checked, ':group_id' => $group_id));
    while($row = $sql->fetch(PDO::FETCH_ASSOC) ) {
        $row1[] = $row;
    }
}
}

相关问题