DanInMA suggested I start a new thread 
I've got a fine looking search box with a JQuery autocomplete that looks impressive at first glance.
I'm trying to make it work for multiple terms --- "foobar" works fine, but the script stops matching and suggesting (in the browser) after a space, so "foobar baz" won't be matched. Watching in Firebug, I see the serviceURL is still providing matching data, so I'm pretty sure the problem is located somewhere on the Javascript side. I've spent more time than I should reading similar threads in places like StackOverflow and have a thread over at PHPBuilder as well, but the last advice there was that I should use PHP's json_encode() ... and that's not the point ... AAMOF it's not been working with json_encode.
Anyway, here's the stuff:
In the HTML header of the search page:
Code:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="includes/jquery.autocomplete.js"></script>
I've attached the latter *js file.
In the page itself:
Code:
<script type="text/javascript">
var a = $('#searchbox').autocomplete({
serviceUrl:'autocomplete.php',
minChars:3,
multiple: true,
multipleSeparator: " ",
delimiter: /(,|;)\s*/, // regex or character
maxHeight:400,
width:300,
zIndex: 9999,
deferRequestBy: 0, //miliseconds
noCache: false //default is false, set to true to disable caching
//callback function:
// local autosugest options:
//local lookup values
});
</script>
Here's Autocomplete.php:
PHP Code:
<?php
// autocomplete.php --- feeds suggestions to
// the AJAX autocomplete (Java)script on our searchbox.
/* According to the docs for the JQuery plugin, we must
echo the output EXACTLY as shown (a modified JSON).
Third list ("data") is optional.
{
query:'Li',
suggestions:['Liberia','Libyan Arab Jamahiriya','Liechtenstein','Lithuania'],
data:['LR','LY','LI','LT']
}
*/
// connect to the DB
include "includes/functions/db.func.php";
$connect=dbConn();
if (!$connect) die("DB connection failed");
if(isset($_GET['query']) && $_GET['query'] != '') {
$jsonout=array();
$qr=($_GET['query']);
$qr=urlencode(mysql_escape_string($qr));
$dbquery="select title from our_table where live=1 and title like '%$qr%' limit 15";
$result = mysql_query($dbquery);
if (!$result) exit;
$replacer=array("\n","\r\n","<br>","<br />","<BR>");
while ($row = mysql_fetch_row($result)) {
$jsonout[] = str_replace($replacer," ",urldecode($row[0]));
}
// return the array as json with PHP
echo "{
query:'".$qr."',
suggestions:[";
$counter=1; $count=count($jsonout);
foreach ($jsonout as $jj) {
echo "'".$jj."'";
if ($counter<$count) {
echo ",";
}
$counter++;
}
echo "]
}
";
}
// logging routine omitted
?>
Thanks very much, in advance, for any hints or clue-stick clobbers.
Bookmarks