0

我正在实时搜索健康卡号码。它与 MySQL 数据库链接,并且在大多数情况下它可以工作......有点。我遇到了一个问题,其中某些数字字符串似乎会给它带来麻烦的字符串,例如 12345689999(我的七键坏了)。它似乎是在一个又一个重复使用相同的字符时出现的。我的 HCN 数据库中的数据类型是文本。我的代码如下:

HTML

<div class="container-fluid">

         <div class="jumbotron">

             <h1 class="display-3">Search Patient Using Health Card Number</h1>
             <hr class="m-y-2">

             <p class="lead">

                 <input type="text" class="form-control" id="hcnSearch" aria-describedby="hcn" placeholder="Search health card number">

             </p>

        </div>

        <div id="result">

        </div>

    </div>

jQuery / AJAX

$(document).ready(function(){

            $("#hcnSearch").keyup(function() {

                var txt =$(this).val();

                if (txt != '') {

                    $('#result').html('');

                    $.ajax({
                        url:"fetch2.php",
                        method: "post",
                        data:{search2:txt},
                        dataType:"text",
                        success:function(data)
                        {
                            $('#result').html(data);
                        }
                    });


                } else {

                    $('#result').html('');
                }

            });
        });

在我的 fetch2.php 文件中

<?php
session_start();

include("connection.php");

$output = '';

$sql = "SELECT * FROM PATIENT_ID_DEMO WHERE H_CARD_NUMBER LIKE '%".mysqli_real_escape_string($link, $_POST["search2"])."%'";

$result = mysqli_query($link, $sql);

if (mysqli_num_rows($result) > 0) {


  while ($row = mysqli_fetch_array($result)) {

      if ($row[5] == 1) {
          $row5 = "Yes";
      } else {
          $row5 = "No";
      }

      if ($row[8] == "M") {
          $row8 = "Male";
      } else {
          $row8 = "Female";
     }

      $output .= '<h4 align="center">Search Result</h4>';  
      $output .= '<div class="table-responsive">  
                    <table class="table table bordered">  
                        <tr>  
                            <th>First Name</th>
                            <th>Last Name</th>
                            <th>Middle Name</th>
                            <th>DOB</th>
                            <th>NS health card</th>
                            <th>Health card number</th>
                            <th>Gender</th>
                            <th>Age</th>
                            <th>UID</th>
                        </tr>';  

  while($row = mysqli_fetch_array($result))  
  {  
       $output .= '  
            <tr>  
                <td>'.$row[1].'</td>
                <td>'.$row[2].'</td>
                <td>'.$row[3].'</td>
                <td>'.$row[4].'</td>
                <td>'.$row5.'</td>
                <td>'.$row[7].'</td>
                <td>'.$row8.'</td>
                <td>'.$row[9].'</td>
                <td>'.$row[10].'</td>
            </tr>  
       ';  
  }  
  echo $output;

}

} else {

   echo "No data found...";

}


?>

此代码允许我输入(搜索)12345689,查询将显示一些相关的健康卡号码,但是如果我正在寻找 12345689999 并输入第二个 9 ......所有搜索都会消失。

4

1 回答 1

0

将方法更改为GET

$.ajax({
         url:"fetch2.php",
         method: "GET",
         data:{search2:txt},
         dataType:"text",
         success:function(data)
         {
           $('#result').html(data);
         }
      });
于 2016-08-24T07:30:18.623 回答