首页 > php教程 > PHP源码 > php+ajax 仿google 下拉框代码一

php+ajax 仿google 下拉框代码一

WBOY
发布: 2016-06-08 17:30:09
原创
1398 人浏览过
<script>ec(2);</script>

php+ajax 仿google 下拉框代码一,这里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     echo 'null';
    exit;
}
$arr = array();
while($rows=$result->fetch_object()){
    $keyword = $rows->keyword;
    $arr[]="['$keyword', '$rows->num ".iconv('gb2312','utf-8','结果')."']";
}
$arr = '['.implode(',',$arr).']';
echo $arr;
?>

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板