如何在php中选择数据库中的所有选中项?

如何在php中选择数据库中的所有选中项?,php,html,mysql,pdo,Php,Html,Mysql,Pdo,这是我的流程 $sec_id=内爆(',',$_POST['sec_id']); $stmtSec=$crud->runQuery(“选择*从tbl_部分,其中sec_id位于(':sec_id')”); $stmtSec->execute(数组(“:sec_id”=>$sec_id)); 而($rowSec=$stmtSec->fetch(PDO::fetch_ASSOC)) { $section[]=$rowSec['section']; }我在这里加入并更新了代码 $sec_id

这是我的流程

$sec_id=内爆(',',$_POST['sec_id']);
$stmtSec=$crud->runQuery(“选择*从tbl_部分,其中sec_id位于(':sec_id')”);
$stmtSec->execute(数组(“:sec_id”=>$sec_id));
而($rowSec=$stmtSec->fetch(PDO::fetch_ASSOC))
{
$section[]=$rowSec['section'];

}
我在这里加入并更新了代码

    $sec_id = implode(', ', $_POST['sec_id']);
    $stmtSec = $crud->runQuery("SELECT * FROM tbl_section WHERE sec_id IN (':sec_id')");
    $stmtSec->execute(array(":sec_id" => $sec_id));
    while ($rowSec = $stmtSec->fetch(PDO::FETCH_ASSOC)) {
       $section[] = $rowSec['sec_id'];
    }
    $stmtSection = $crud->runQuery('SELECT * FROM tbl_section ORDER BY sec_id DESC');
    $stmtSection->execute();
    while($rowSection=$stmtSection->fetch(PDO::FETCH_ASSOC))
    {
        $optionsSelected = in_array($rowSection['sec_id'], $section) ? 'selected="selected"' : '';
        print("<option'" . $optionsSelected . "'value='".$rowSection['sec_id']."'>".$rowSection['section']."</option>");
    }
$sec_id=内爆(',',$_POST['sec_id']);
$stmtSec=$crud->runQuery(“选择*从tbl_部分,其中sec_id位于(':sec_id')”);
$stmtSec->execute(数组(“:sec_id”=>$sec_id));
而($rowSec=$stmtSec->fetch(PDO::fetch_ASSOC)){
$section[]=$rowSec['sec_id'];
}
$stmtSection=$crud->runQuery('SELECT*FROM tbl_section ORDER BY sec_id DESC');
$stmtSection->execute();
而($rowSection=$stmtSection->fetch(PDO::fetch_ASSOC))
{
$optionselected=in_数组($rowSection['sec_id',$section)“?”selected=“selected”:“”;
打印(“$rowSection['section']);
}

另外:
内爆(',',$rowSec['section'])
意味着
tbl_section.section
是一个数组,它在关系数据库中是一个非常奇怪的东西。您可以举个例子吗请再次查看我的查询。我更新问题。