p id="ptselect"
input id="ptselect_c" name="ptselect" type="text" /
/p
scrip
$(function(){
setAutoComplete("ptselect_c", "results", "autocomplete.php?part=");
});
/script
autocomplete.php
include"dbcon.php";
$result = mysql_query("SELECT concat( FirstName,' ', LastName,' ',OfficerNo) as name
FROM `legalofficers` ORDER BY FirstName ASC");
while ($row = mysql_fetch_assoc($result)) {
$colors[]=$row['name'];
}
mysql_free_result($result);
// check the parameter
if(isset($_GET['part']) and $_GET['part'] != '')
{
// initialize the results array
$results1 = array();
// search colors
foreach($colors as $color)
{
// if it starts with 'part' add to results
if( strripos($color, $_GET['part']) === 0 ){
$results1[] = $color;
}
}
// return the array as json with PHP 5.2
echo json_encode($results1);
}
No comments:
Post a Comment