Jquery, ajax, PHP - Live search not returning values in some situations -


i have live search going health card numbers. linked mysql database , part works... kinda. im running problem strings of numbers seem give trouble strings such 12345689999 (my 7 key broken). seems appear when there same characters used repeatedly after 1 another. data type in database hcn's text. code follows:

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('');                 }              });         }); 

in fetch2.php file

<?php session_start();  include("connection.php");  $output = '';  $sql = "select * patient_id_demo h_card_number '%".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...";  }   ?> 

this code allows me type (search) 12345689 , query show relevant health card numbers if looking for12345689999 , type second 9... of searches go away.

change method get

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

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -