I have an auto-complete search field in which as the user types a name, the results are shown in the dropdown. And it works fine.
I want to make each result a link, so that when the results are shown the user can click on the correct name and it will take them to their profile.
See script below:
<input type='text' id=employees class='form-control' size="80" placeholder="Search Employees by first or last name">
search.php
$searchTerm = $_GET['term'];
$sql = mysql_query ("SELECT name_first, employee_id, unique_id, name_last FROM hr_employees WHERE name_first LIKE '{$searchTerm}%' OR name_first LIKE '{$searchTerm}%' OR employee_id LIKE '{$searchTerm}%'");
$array = array();
while ($row = mysql_fetch_array($sql)) {
$array[] = array (
'value' => $row['name_first'].' '.$row['name_last'].' ('.$row['employee_id'].')',
);
}
//RETURN JSON ARRAY
echo json_encode ($array);
Upon selecting the correct user, I want the user to be redirected to page.php?id=$employee_id
JavaScript
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
JavaScript
<script>
$(function() {
$( "#employees" ).autocomplete({
source: 'search.php'
});
});
</script>
Is this possible? If yes how can I do this?