so I have this code which I'm using for a search box(like we have in google, the autosearch). In this below example, the values are hard-coded, but, I would need to have dynamic values in the array.
Here's the code :-
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Autocomplete - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
$( "#tags" ).autocomplete({
source: availableTags
});
});
</script>
</head>
<body>
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags">
</div>
</body>
</html>
How would I have a dynamic array in this place? You may suppose that I have a variable $row which gets the data(search options) dynamically from a mysql database.
Thank you.
Edit :-
The php code which fetches the value :-
<?php
include 'dbconnector.php';
$query="SELECT firstname from users order by userid";
$result=mysql_query($query,$db) or die (mysql_error($db));
$row=mysql_fetch_array($result);
?>
$rowto json in a php file then use that php file as the source for the auto-complete. Use this tutorial as a reference bit.ly/1gj2DDM