I am building a website to learn PHP and am doing autosuggest from Jquery Ui.
Here is my code (I made it from the SO post a long time ago, and I'm not 100% what it does, so if someone could explain it, it would be useful!) This code is from a suggestion. php that I call from my jQuery code (which I think works, so I did not publish it, but I 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 does the work with startup, but only with the same results (for example, if I type “Jones”, “Johns Hot Dogs” appears as a sentence, but if I type “fjfjdjf669959” then this will happen with “Johns Hot Dogs "
I am doing Mysql Union because I am trying to populate my autosuggest with the name row from the company table, cat rows from the cat table and sub- lines < from the sub- tables < .
Why is this not working?
Thanks for any help!
My JQUERy code is as follows:
<script> $(function() { $( "#search" ).autocomplete({ source: "suggest.php" }); }); </script>
source share