From startPage.php:
Code: Select all
<form>
First Name:
<input type="text" id="txt1"
onkeyup="showHint(this.value)">
</form>
<p>Suggestions: <span id="txtHint"></span></p>The javascript file references search.ajax.php, which executes this code (a snippet of the main code):
Code: Select all
<?php
$sqlDb->query("query is here");
$ajax = new ajaxScript;
$array = $sqlDb->parseArraySingleField("name");
$count = $sqlDb->countParseArraySingle("name");
//get the q parameter from URL
$query = $ajax->setParamFromUrl("query");
echo $ajax->returnArrayValuesAsString($array, $query, $count);
?>ajax.class.php:
Code: Select all
<?php
include "mssql.class.php";
class ajaxScript {
//get the q parameter from URL
function setParamFromUrl($param) {
$get = $_GET[$param];
return $get;
}
function returnArrayValuesAsString($array, $query, $count) {
if (strlen($query) > 0) {
$hint = "";
//$hint = "$array[0]";
//$hint = "$count";
$count = 30;
for($i=0; $i < $count; $i++) {
if (strtolower($query) == strtolower(substr($array[$i], 0, strlen($query)))) {
if ($hint == "") {
$hint = $array[$i];
} else {
$hint = $hint." , ".$array[$i];
}
}
}
if ($hint == "") {
$response = "no user by this login";
} else {
$response = $hint;
}
}
return $response;
}
}
?>Code: Select all
function parseArraySingleField($field) {
$counter = 0;
while ($results = $this->fetchArray()) {
$array[$counter] = $results[$field];
$counter++;
}
return $array;
}
function countParseArraySingle($field) {
$counter = 0;
while ($results = $this->fetchArray()) {
$array[$counter] = $results[$field];
$counter++;
}
return $counter;
}Jimmy