想要使用PDO进行复选框筛选


Want to make a checkbox filter using PDO

我想用PDO做一个复选框过滤器,但我不知道怎么做。在尝试了很长一段时间并在互联网上搜索后,我仍然没有运气。

我试图展示我所做的所有项目(这些项目取自数据库),并将它们显示在一个名为gallery的<div>中。左边是一个名为helpbar的栏,带有复选框(也取自数据库)。

websoft表包括我所有的项目,filter表包括所有的filter选项(如网站和应用程序)。

<div class="container">
    <div class="helpbar">
        <div class="helpbar-block">
        <?php $query=$db->prepare("SELECT * FROM `portfoliodb`.`filter`");
        $query->execute();
        while   ( $row = $query->fetch()) {
            $filter_id = $row['filter_id'];
            $filter_name = $row ['filter_name'];
            echo'<table class="helpbar-table">
                    <tr> <td><input type="checkbox" name ="websoft" checked class="filter-checkbox">'; echo htmlspecialchars($filter_name); echo'</td></tr>
                 </table>';
        }?>
        </div>
    </div>
    <div class="gallery">
        <?php   $query=$db->prepare("SELECT * FROM `portfoliodb`.`websoft`");
        $query->execute();
        while   ( $row = $query->fetch()){
            $websoft_id = $row['websoft_id'];
            $websoft_name = $row ['websoft_name'];
            $websoft_desc_en = $row ['websoft_desc_en'];
            $websoft_img = $row ['websoft_img'];
            $websoft_type = $row ['websoft_type'];
            echo'<a><div class="gallery-item">
                <p class="gallary-item-text">';
                 echo htmlspecialchars($websoft_name);
                echo'</p></div></a>';

websoft_type基本上意味着过滤器(所以如果它是一个网站,那么websoft_type = website)。

我希望你能理解这个相当愚蠢的代码,并帮助我解决我的问题。感谢您的时间和回答。

--编辑--

如果过滤系统不是由数据库控制的,这是没有问题的,如果这样做更容易的话。

我通过更改数据库并添加if/else语句基本上解决了这个问题。