在一个表单中使用多个typeahead

swvgeqrz  于 2021-06-25  发布在  Mysql
关注(0)|答案(0)|浏览(243)

我目前正在创建一个表单,将创建一个'预约或访问'的医生。
表单将包括选择病人、医生、病情、药物,并使用id作为外键将其保存到链接表中(所有这些都来自单独的表)。
但是为了完成这个表单,我使用的是typeahead,当它只在表单中使用一次时,它就工作了,但是一旦我添加了多个typeahead,它就停止工作了。
我是一个新的php和学习,所以如果我在完全错误的地方,指导将不胜感激:)
我的代码如下。
索引.html

<html>
      <head>
        <title>Search</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
        <link rel="stylesheet" href="style.css">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
        <script src="typeahead.min.js"></script>
        <script>
        $(document).ready(function(){
        $('input.typeahead').typeahead({
            name: 'patient',
            remote:'search.php?patientkey=%QUERY',
            limit : 10
        });
    });

        $(document).ready(function(){
        $('input.typeahead').typeahead({
            name: 'doctor',
            remote:'search.php?doctorkey=%QUERY',
            limit : 10
        });
    });

        $(document).ready(function(){
        $('input.typeahead').typeahead({
            name: 'con',
            remote:'search.php?conkey=%QUERY',
            limit : 10
        });
    });

        $(document).ready(function(){
        $('input.typeahead').typeahead({
            name: 'med',
            remote:'search.php?medkey=%QUERY',
            limit : 10
        });
    });
        </script>
      </head>
      <body>
      <div class=".col-md-6">
        <div class="panel panel-default">
        <div class="bs-example">
            <input type="text" name="patient" class="typeahead tt-query" autocomplete="on" spellcheck="on" placeholder="Type Patient Name">
            <input type="text" name="doctor" class="typeahead tt-query" autocomplete="on" spellcheck="on" placeholder="Type Doctor Name">
            <input type="text" name="con" class="typeahead tt-query" autocomplete="on" spellcheck="on" placeholder="Type Condition">
            <input type="text" name="med" class="typeahead tt-query" autocomplete="on" spellcheck="on" placeholder="Type Medication">

        </div>
      </div>
      </div>
      </div>
      </body>
    </html>

搜索.php

<?php // Include config file < includes $db connection
include("$_SERVER[DOCUMENT_ROOT]/freddies/inc/config.php");
?>
<?php
    $patientkey=$_GET['patientkey'];
    $array = array();
    $query=mysqli_query($db, "select * from patient where sName or FName LIKE '%{$patientkey}%'");
    while($row=mysqli_fetch_assoc($query))
    {
      $array[] = $row['fName']." ".$row['sName'];
    }
    echo json_encode($array);
    mysqli_close($db);

    $doctorkey=$_GET['doctorkey'];
    $array = array();
    $query=mysqli_query($db, "select * from doctor where sName or FName LIKE '%{$doctorkey}%'");
    while($row=mysqli_fetch_assoc($query))
    {
      $array[] = $row['fName']." ".$row['sName'];
    }
    echo json_encode($array);
    mysqli_close($db);

    $conkey=$_GET['conkey'];
    $array = array();
    $query=mysqli_query($db, "select * from med where con_name LIKE '%{$conkey}%'");
    while($row=mysqli_fetch_assoc($query))
    {
      $array[] = $row['con_name'];
    }
    echo json_encode($array);
    mysqli_close($db);

    $medkey=$_GET['medkey'];
    $array = array();
    $query=mysqli_query($db, "select * from drugs where medication LIKE '%{$medkey}%'");
    while($row=mysqli_fetch_assoc($query))
    {
      $array[] = $row['medication'];
    }
    echo json_encode($array);
    mysqli_close($db);
?>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题