使用复选框[PHP] [MYSQL]

时间:2017-07-13 16:13:05

标签: php mysql checkbox filter

在我的网站上有一个页面,其中显示了我的数据库的内容(所有本地人的列表)。我想让用户过滤研究,所以我希望我的查询显示resoults可以通过复选框修改。如果用户在复选框中选择素食主义者,则该页面必须仅显示素食本地人。我没有复选框的表单,所以我不知道处理输入的热情。 我有两个脚本: locals_page.php ,它是带有过滤器框的主页面和 table_generator.php ,它是一个用于执行查询和检索数据的php脚本,以及将它们显示到locals_page.php

我搜索了很多来解决这个问题,但我不知道如何开始,因为我没有一个简单的表格用于重新组合或共同形式。

也许这是一般性问题,但我们将不胜感激。

locals_page

<body>
    <div class="container">
        <div class="row">
            <!--FILTERS PART-->
            <div class="col-sm-3 col-md-3">
                <div class="panel-group" id="accordion">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <h4 class="panel-title">
                                <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne"><span class="glyphicon glyphicon-folder-close">
                                </span>Kitchen type</a>
                            </h4>
                        </div>
                        <div id="collapseOne" class="panel-collapse collapse in">
                            <div class="panel-body">
                                <table class="table">
                                    <tr>
                                        <td>
                                            <input type="checkbox" name="Kebab" value="Kebab"> Kebab
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <input type="checkbox" name="Asiatic" value="Asiatic"> Asiatic
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <input type="checkbox" name="Vegan" value="Vegan"> Vegan
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </div>
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <h4 class="panel-title">
                                <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo"><span class="glyphicon glyphicon-th">
                                </span>Local Type</a>
                            </h4>
                        </div>
                        <div id="collapseTwo" class="panel-collapse collapse">
                            <div class="panel-body">
                                <table class="table">
                                    <tr>
                                        <td>
                                            <input type="checkbox" name="Restaurant" value="Restaurant"> Restaurant
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <input type="checkbox" name="Pub" value="Pub"> Pub
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--END FILTERS PART-->
            <div class="col-sm-9 col-md-9">
                <!--SCRIPT THAT GENERATE MY PAGE-->
                <?php require_once('php\table_generator.php'); ?>
            </div>
        </div>
    </div>
</body>

table_generator

<?php
    echo '<section class="col-xs-12 col-sm-6 col-md-12">';
    $sql = "SELECT nome_L, tipocucina_TC, wifi_L, tipolocale_TL, descrizione_L, indirizzo_L, fasciaprezzo_L, convenzione_L FROM locale l 
                        JOIN tipocucina c On l.TipoCucina_L = c.IDtipocucina_TC
                        JOIN tipolocale t On l.TipoLocale_L = t.IDTipolocale_TL";
    $result = mysqli_query($conn, $sql) or die(mysqli_error($conn));
    while ($row = mysqli_fetch_array($result)) {
        $nome_Local        = $row['nome_L'];
        $descrizione_Local = $row['descrizione_L'];
        $indirizzo_Local   = $row['indirizzo_L'];
        $tipocucina_Local  = $row['tipocucina_TC'];
        $tipolocale_Local  = $row['tipolocale_TL'];
        $wifi_Local        = $row['wifi_L'];
        $prezzo_Local      = $row['fasciaprezzo_L'];
        //Inizio article
        echo '<article class="search-result row">
            <div class="col-xs-12 col-sm-12 col-md-3">
                <a class="thumbnail"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e6/Piadina.jpg/1200px-Piadina.jpg" alt="Lorem ipsum" /></a>
            </div>
            <div class="col-xs-12 col-sm-12 col-md-2" style="width: 18%;">
                <ul class="meta-search">
                    <li><i class="fa fa-cutlery fa-lg"></i> <span>' . $tipocucina_Local . '</span></li>
                    <li><i class="fa fa-coffee fa-lg"></i> <span>' . $tipolocale_Local . '</span></li>
                    <li><i class="fa fa-coffee fa-lg"></i> <span>' . $wifi_Local . '</span></li>
                    <li><i class="fa fa-coffee fa-lg"></i> <span>' . $prezzo_Local . '</span></li>
                </ul>
            </div>
            <div class="col-xs-12 col-sm-12 col-md-7 excerpet" style="width: 55%;">';

        echo "<h3><a>" . $nome_Local . "</a></h3>";
        echo '<i class="fa fa-compass"> </i>' . $indirizzo_Local . '</i>';
        echo "<br>";
        echo '<p class="local-description">' . $descrizione_Local . '</p>';
        echo '
                </div>
                <span class="clearfix borda"></span>
            </article>'; //Fine article
    }
    $conn->close();
    echo "</section>";
?>

我不知道是否需要javascript或ajax或jquery。我不知道如何开始。我希望我的问题是可以理解的,我提出的代码是有帮助的。非常感谢你的建议。

0 个答案:

没有答案