Right now I have a site that has a dropdown menu, and in that menu contains about 1200 locations of different places. What I want to do is replace that dropdown menu with a textbox and when the user starts typing in the name of the location, it will populate the list accordingly. I have been able to do this successfully using an array that I create in the actual script block of my code, but what I want to do is not replace that with the data that comes from a MySQL query from an external php file. This is what I have working using the array.
Here is the php associated with this question:
<?php
include('common.php');
$sql = "SELECT LoginUserName FROM LoginUser";
$query = mysql_query($sql);
while ($row = mysql_fetch_array($query)) {
$users = $row['LoginUserName'];
//echo $hour.":".$minutes;
}
// $timeHour = $_POST['hours']; This isn't needed.
echo $users;
$content = $_POST['users']; //get posted data
?>
Here is what I currently have working using the array hard coded
<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>
And then the html used on the page is
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags" />
</div>
So now what I am trying to do is to to use AJAX to call the php script which has the MySQL query and return what it gets and in turn populate the search results to have the same effect. Here is what I have come up with, keep in mind I am still new to the jQuery / AJAX thing...
<script>
$(function() {
var availableTags = [
$.ajax({
type: "POST",
url: "getme.php",
data: { content: content
}
})
];
$( "#tags" ).autocomplete({
source: availableTags
});
});
</script>
Any help is greatly appreciated. Thank you very much in advance