单击搜索按钮时,搜索查询会显示所有结果

时间:2016-03-17 09:41:30

标签: php html mysql .htaccess

我有一个简单的搜索查询,但在没有搜索输入的情况下单击搜索按钮时会显示所有结果。

它还显示了我想在查询中阻止的parent_id 26或cattid 26的结果。为什么它仍然显示那些id的结果?如果没有搜索输入,如何防止结果页面上出现的每个结果?

如何构建:

HTML:

<li>
    <div class="mn-wrap">
        <form method="post" class="form" action="zoeken/">
            <div class="search-wrap">
                <button class="search-button animate" type="submit" title="Start zoeken">
                    <i class="fa fa-search"></i>
                </button>
                <input type="text" name="zoekterm" class="form-control search-field" placeholder="Zoek...">
            </div>
        </form>
    </div>
</li>

htaccess的:

RewriteRule         ^zoeken/ /zoeken.php?zoeken=1 [L]

查询:

if ($_GET['zoeken'] != '') {

    $zoekterm = $_POST['zoekterm'];

    // zoeken
    $zoeken    = "SELECT * FROM `lb_content` WHERE catid NOT IN ('1', '26', '27', '28') and  introtext LIKE '%".$conn->real_escape_string($zoekterm)."%' OR title LIKE '%".$conn->real_escape_string($zoekterm)."%'";
    $zoekencon = $conn->query($zoeken);
    $zoekeni   = array();
    while ($zoekeni[] = $zoekencon->fetch_array());

    // zoeken c
    $zoekc    = "SELECT * FROM `lb_categories` WHERE parent_id NOT IN ('1', '26', '27', '28') and level = 2 and description LIKE '%".$conn->real_escape_string($zoekterm)."%' OR title LIKE '%".$conn->real_escape_string($zoekterm)."%'";
    $zoekccon = $conn->query($zoekc);
    $zoekci   = array();
    while ($zoekci[] = $zoekccon->fetch_array());
}

最后是结果页面:

<div class="row multi-columns-row alt-features-grid">

    <?

    $aantal = count($zoekeni) + count($zoekci) - 2;

    if($aantal == 0){

        echo '<div class="col-sm-6 col-md-4 col-lg-4">
                    <div class="alt-features-item align-center">
                        <div class="alt-features-icon">
                        </div>
                        <h3 class="alt-features-title font-alt">Er zijn geen resultaten</h3>
                    </div>
                </div>';
    }

    if($zoekeni[0]['id']){
        foreach ($zoekeni as $resultaat) {

            if($resultaat['introtext']){

                echo '

                    <div class="col-sm-6 col-md-4 col-lg-4">
                        <div class="alt-features-item align-center">
                            <div class="alt-features-icon">
                            </div>
                            <h3 class="alt-features-title font-alt">'.$resultaat['title'].'</h3>
                            <div class="alt-features-descr align-left">
                                '.IntroText($resultaat['introtext']).'<br><br>
                                 <div class="align-right">
                                    <a href="'.$resultaat['alias'].'.html" style="text-decoration:none">Lees meer</a>
                                </div>
                            </div>
                        </div>
                    </div>

                ';

            }

        }
    }


    if($zoekci[0]['id']){
        foreach ($zoekci as $resultaat) {

            if($resultaat['description']){

                echo '

                    <div class="col-sm-6 col-md-4 col-lg-4">
                        <div class="alt-features-item align-center">
                            <div class="alt-features-icon">
                            </div>
                            <h3 class="alt-features-title font-alt">'.$resultaat['title'].'</h3>
                            <div class="alt-features-descr align-left">
                                   '.IntroText($resultaat['description']).'<br><br>
                                 <div class="align-right">
                                    <a href="'.$resultaat['alias'].'.html" style="text-decoration:none">Lees meer</a>
                                </div>
                            </div>
                        </div>
                    </div>

                ';

            }

        }
    }

    ?>

</div>

0 个答案:

没有答案