实时搜索结果未显示

时间:2019-05-06 21:22:07

标签: php jquery html mysql

http://flask.pocoo.org/docs/1.0/patterns/sqlalchemy/ <-链接到index.html,使用西班牙语。

我正在跟踪有关如何设置实时搜索结果的教程,因为我正在尝试构建“组”目录,在尝试连接数据库之前,它运行良好,因此我测试了jQuery而且它确实有效,当您输入两个以上的单词时,它会显示文本,但是当我尝试在该数据库中搜索实际数据时,无法显示任何结果。我在名为“后端”的文件中使用代码,例如:

backend.php

<?php
include 'db.inc.php';

if(isset($_POST['search'])){
    $search = $_POST['search'];
    $search = "%$search%";

    if(strlen($search) > 2) {
        $sql = "SELECT * FROM directorio_grupos_aa_sonora_sur WHERE grupo LIKE :s || ciudad LIKE :s || reuniones LIKE :s || direccion LIKE :s";

        $stmt = $db->prepare($sql);
        $stmt->bindParam('s',$search);
        $stmt->excecute();

        while($row = $stmt->fetch()){
            $grupo = $row['grupo'];
            $horario = $row['horario'];
            $reuniones = $row['reuniones'];
            $rsg = $row['rsg'];
            $periodo = $row['periodo'];
            $email = $row['email'];
            $telefono = $row['telefono'];
            $direccion = $row['direccion'];
            $ciudad = $row['ciudad'];

            echo "<div>$grupo $reuniones</p>$horario<br>$direccion<br>$ciudad<br>$rsg $telefono $periodo<br>
            <a href='mailto;$email>$email</a></div>";
        }
    }
}
?>

“ db.inc.php”处理与数据库的连接,例如:

<?php
try{
    $db = new pdo('mysql:host=localhost;dbname=id9021430_directorio42;charset=utf8','id9021430_directorioaa', 'serviresvivir');}
    catch(PDOException $e){die($e->getMessage());}
?>

,至少在输入端位于index.html文件中:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
        <script>

            $(document).ready(function() {
              $("#search").keyup(function(){
                $.ajax({
                  url: 'backend.php',
                  type: 'post',
                  data: {search: $(this).val()},
                  success:function(result){
                    $("#result").html(result);
                  }
                });
              });
            });

            </script>

<section class="container">

  <div class="row">
<div class="col-lg-5">

  <h2>Quick search</h2>
<p>Find groups: </p>
  <input type="text" id="search" />
  </p>
  <span id="result"></span>

</div>
</div>

</section>

那么,问题出在哪里?

0 个答案:

没有答案