Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.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_Database - Fatal编程技术网

Php 如何用可折叠方法显示产品带和型号

Php 如何用可折叠方法显示产品带和型号,php,database,Php,Database,如何以可折叠的方式显示产品过滤器的品牌和型号?目前,我使用以下代码过滤数据表单SQL PHP <div class="card-body pt-1" style="overflow-y: scroll; height:150px;"> <?php $sca = 'Car'; try { $stmt = $conn->prepare("SELECT DISTINCT(product_brand) FROM allpostdata WH

如何以可折叠的方式显示产品过滤器的品牌和型号?目前,我使用以下代码过滤数据表单
SQL

PHP

<div class="card-body pt-1" style="overflow-y: scroll; height:150px;">
    <?php
    $sca = 'Car';
    try {
        $stmt = $conn->prepare("SELECT DISTINCT(product_brand) FROM allpostdata WHERE sca=:sca ORDER BY (product_brand)");
        $stmt->bindParam(':sca', $sca, PDO::PARAM_STR);
        $stmt->execute();
        $result = $stmt->fetchAll();
        foreach ($result as $row) {
            ?>
            <div class="custom-control custom-checkbox">
                <input type="checkbox" class="custom-control-input common_selector filter_all brand" id="<?php echo $row['product_brand']; ?>" value="<?php echo $row['product_brand']; ?>">
                <label class="custom-control-label" for="<?php echo $row['product_brand']; ?>"><?php echo $row['product_brand']; ?></label>
            </div>
    <?php
        }
        $dbh = null;
    } catch (PDOException $e) {
        echo $e->getMessage();
    }
    ?>
</div>

对于车型

<div class="card-body pt-1" style="overflow-y: scroll; height:150px;">
    <?php
    $sca = 'Car';
    try {
        $stmt = $conn->prepare("SELECT DISTINCT(product_model) FROM allpostdata WHERE sca=:sca ORDER BY (product_model)");
        $stmt->bindParam(':sca', $sca, PDO::PARAM_STR);
        $stmt->execute();
        $result = $stmt->fetchAll();
        foreach ($result as $row) {
            ?>
            <div class="custom-control custom-checkbox">
                <input type="checkbox" class="custom-control-input common_selector filter_all brand" id="<?php echo $row['product_model']; ?>" value="<?php echo $row['product_model']; ?>">
                <label class="custom-control-label" for="<?php echo $row['product_model']; ?>"><?php echo $row['product_model']; ?></label>
            </div>
    <?php
        }
        $dbh = null;
    } catch (PDOException $e) {
        echo $e->getMessage();
    }
    ?>
</div>

但我该如何展示形象中给出的品牌和型号都是可折叠的


您需要一点javascript来完成that@Kevinjavascript。。?任何示例都不要捕获异常只是为了响应它。这是一种糟糕的做法。@Dharman有没有其他方法来实现这种方法?是的,只需删除try/catch块。我不确定这是否就是你所说的方法。