/    Sign up×
Community /Pin to ProfileBookmark

Jquery Autocomplete

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:

[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>
[/CODE]

[code=php]
<?php
ob_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();
}
?>
[/code]

sample:

employee_no = BN262
employee_name = Anna
passport_no = 12345
res_id = 54321

when i type BN the list display should be all employee_no with BN but in my code it display the list of employee name with BN employee_no.

Thank you

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @newphpcoder spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...