-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgethint.php
61 lines (53 loc) · 1009 Bytes
/
gethint.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
// Fill up array with names
$conn = odbc_connect('comb','','');
if (!$conn)
{
die("Connection Failed");
}
$sql = "SELECT realname FROM ACE";
$rs = odbc_exec($conn, $sql);
if (!$rs)
{
die("Error in SQL");
}
function enc($c){return iconv('utf-8', 'gbk', $c);}
function arcenc($c){return iconv('gbk', 'utf-8', $c);}
while (odbc_fetch_row($rs))
{
$a[] = arcenc(odbc_result($rs, "realname"));
}
odbc_close($conn);
// get the q parameter from URL
$q = $_GET["q"];
// look up all hints from array if length of q>0
if (strlen($q) > 0)
{
$hint = "";
for ($i=0; $i<count($a); $i++)
{
if ($q == substr($a[$i], 0, strlen($q)))
{
if ($hint == "")
{
$hint = "<div onclick='fet(this)'>" . $a[$i] . "</div>";
}
else
{
$hint = $hint . "<div onclick='fet(this)'>" . $a[$i] . "</div>";
}
}
}
}
// Set output to "no suggestion" if no hint were found
// or to the correct values
if ($hint == "")
{
$response = "no suggestion";
}
else
{
$response = $hint;
}
echo $response;
?>