I'm building a website to learn PHP and am making an autosuggest from Jquery Ui.
Here's my code ( I took this code from a post on SO a long time ago, and I'm not 100% what it does, so if anyone could explain, it would be helpful!) This code is from suggest.php, which I call to from my jquery code (which I think is working, so I didn't post it, but can If you need it!)
<?
include("config.php");
$queryString = strtolower($_GET["q"]);
$return = array();
$query = mysql_query("SELECT name FROM company WHERE name LIKE '$queryString%' UNION SELECT cat FROM cat WHERE cat LIKE '$queryString%' UNION SELECT subcat FROM subcat WHERE subcat LIKE '$queryString%' LIMIT 10");
while ($row = mysql_fetch_array($query)) {
array_push($return,array('label'=>$row['name'],'value'=>$row['name']));
}
echo(json_encode($return));
?>
Right now this is making the autosuggest work, but only with the same results (example, if I type "Johns" it comes up with "Johns Hot Dogs" as a suggestion, but If I type "fjfjdjf669959" then it comes up with "Johns Hot Dogs" as well.
I'm doing a Mysql Union because I'm trying to populate my autosuggest with the name row from company table, the cat row from cat table, and the subcat row from subcat table.
Why is this not working?
Thanks for any and all help!!
My JQUERy code looks like this:
<script>
$(function() {
$( "#search" ).autocomplete({
source: "suggest.php"
});
});
</script>