--- a/search_autosuggest.php +++ b/search_autosuggest.php @@ -1,1 +1,62 @@ - + "supplier-".$row['id'], + "value" => htmlspecialchars($row['value']) , + "info" => htmlspecialchars("Supplier - ". $row['count']." records") + ); + } + $query = "SELECT agencyName as info, agencyName as id, agencyName as value, count(*) as count +FROM `contractnotice` +WHERE agencyName LIKE '$input%' +GROUP BY agencyName +ORDER BY count DESC +LIMIT 4;"; + $result = mysql_query($query); + while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { + $count++; + $aResults[] = array( + "id" => "agency-".$row['id'], + "value" => htmlspecialchars($row['value']) , + "info" => htmlspecialchars("Government Agency - ". $row['count']." records") + ); + } +} +header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past +header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified +header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 +header("Pragma: no-cache"); // HTTP/1.0 +if (isset($_REQUEST['json'])) { + header("Content-Type: application/json"); + echo "{\"results\": ["; + $arr = array(); + for ($i = 0;$i < count($aResults);$i++) { + $arr[] = "{\"id\": \"" . $aResults[$i]['id'] . "\", \"value\": \"" . $aResults[$i]['value'] . "\", \"info\": \"\"}"; + } + echo implode(", ", $arr); + echo "]}"; +} else { + header("Content-Type: text/xml"); + echo ""; + for ($i = 0;$i < count($aResults);$i++) { + echo "" . $aResults[$i]['value'] . ""; + } + echo ""; +} +?>