Php+ajax Imitation Google dropdown box code one, here the PHP code
<?php
Header (' Content-type:text/html;charset=utf-8 ');
Require ('.. /.. /admin/include/db_conf.php ');
if ($_post[' add ']) {
$keyword = Trim ($_post[' keyword ']);
if (empty ($keyword)) {
Header ("LOCATION:suggest.html");
Exit
}
$db = Db_connect ();
$db->query ("Set names ' gb2312 '");
$sql = "Select*from suggest where keyword = ' $keyword '";
if ($db->query ($sql)->num_rows>0) {
Header ("LOCATION:suggest.html");
Exit
}
$num = rand (15, 2008);
$sql = "INSERT into suggest values (NULL, ' $keyword ', $num)";
$db->query ($sql);
$db = NULL;
Header ("LOCATION:suggest.html");
Exit
}
$keyword = $_post[' keyword '];
if (empty ($keyword)) {
echo ' null ';
Exit
}
$db = Db_connect ();
$db->query ("Set names ' UTF8 '");
$sql = "Select *from suggest where keyword REGEXP ' ^ $keyword ' ORDER BY id desc limit 0, 15";
$result = $db->query ($sql);
if ($result->num_rows<1) {
echo ' null ';
Exit
}
$arr = Array ();
while ($rows = $result->fetch_object ()) {
$keyword = $rows->keyword;
$arr []=] [' $keyword ', ' $rows->num '. Iconv (' gb2312 ', ' utf-8 ', ' result ').
}
$arr = '. Implode (', ', $arr).
Echo $arr;
?>