Thank you, Brad. Here goes:
In the HTML header of the search page:
<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'll try and attach the latter *js file.
In the page itself:
<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
//params: { country:'Yes' }, //aditional parameters
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
// 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 (MUCH!) for offering your help. I can send a working URI via PM if needed. I'll communicate some with you privately if you can help me deploy this with support for spacing - do like you pizza? 😉