在一种形式中使用多个Typeahead

时间:2018-04-18 22:59:04

标签: php mysql json ajax

我目前正在创建一个表格,可以为医生创建“预约或访问”。

表单将包括选择Patient,Doctor,Condition,Medication并将id(所有这些都来自不同的表格)保存到链接表中,使用id作为外键。

但是为了做这个表格,我使用的是Typeahead,它只在表单中使用一次时有效,但是一旦我添加的次数超过了它停止工作的次数。

我对PHP和学习相当新,所以如果我在完全错误的地方,指导将不胜感激:)

我的代码如下。

的index.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>

的search.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);
?>

0 个答案:

没有答案