Jump to content

Jquery Autocomplete

Recommended Posts

Hi,Good day!I created a search box and my problem is when I type Employee ID the auto list displayed is Employee Name, I need to display on the list is based on what I type. I don't know if it is possible that in one search box I can search Employee name then the list of names will display, when I type Employee ID, employee id list will display. same with Passport no and res id.Now, when I type Employee Id or Passport No or res id and employee name. the displayed list is employee name.this is my code:

<script type="text/javascript" src="js/jquery.js"></script>     <script type='text/javascript' src='js/jquery.autocomplete.js'></script>     <link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" /><script type="text/javascript">//----auto complete emp no--//$().ready(function() {  $("#search_data").autocomplete("get_emp_info.php", {  width: 237,    minLength: 3,//search after three characters  matchContains: true,  mustMatch: true,  selectFirst: false  });     });</script>  <table>     <tr>     <td style="border: none;color:#80600a;font-weight:bold;">Search:</td>     <td><input type="text" name="search_data" id="search_data" value="" size="35" autofocus></td>     </tr>     </table>
<?phpob_start();include('includes/connection.php');$q = strtolower($_GET["q"]);if ($q == '') {  header("HTTP/1.0 404 Not Found", true, 404);}//else (!$q) return;else{$sql = "SELECT pe.employee_no, pe.employee_name, pe.passport_no,   gov.res_id   FROM tbl_personal_info AS pe JOIN tbl_public_info AS pu ON (pe.employee_no = pu.employee_no) JOIN tbl_e_government_info AS gov ON (pu.employee_no = gov.employee_no)   WHERE pe.employee_no LIKE '%".$q."%' OR pe.employee_name LIKE '%".$q."%' OR pe.passport_no LIKE '%".$q."%' OR gov.res_id LIKE '%".$q."%'";$result = $conn->query($sql);if ($result->num_rows > 0) {  // output data of each row  while($row = $result->fetch_assoc()) {     $pid = $row["employee_no"];     $employee_name = $row["employee_name"];     $passport_no = $row["passport_no"];     $res_id = $row["res_id"];           echo "$employee_name|$pid|$passport_no|$res_idn";   }} else {  echo "0 results";}$conn->close();  }?>

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...