html 需jq支持
<header><meta http-equiv="Content-Type" content="text/html charset=utf-8">
<script type="text/javascript" src="jsfile/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//$("#tel").val("123")
$("#dk_search").click(function(){
var key = $("#keyword").val()
var data = "uname="+key
//alert(data)
$.get("./k.php",data, function(text){
alert(text)
$("#tel").val(text)
})
})
})
</script>
</header>
<body>
<label for="keyword" width="40">用户名</label>
<input type="text" name="keyword" id="keyword" size="15" value=""/></br>
<label for="tel" width="40" >电 话</label>
<input type="text" id="tel" size="15" value="" /></br>
<input type="submit" id="dk_search" value="读取" >
</body> k.php
<?php
header("Content-Type: text/html charset=utf-8")
$mysqli=new mysqli("127.0.0.1", "root", "123456", "testmysql") //数据库 mysqli对象
if(mysqli_connect_error()){ //
$this->error = mysqli_connect_error()
echo mysqli_connect_error()
return FALSE
}
$mysqli->query("SET NAMES UTF8")
if(!isset($_GET['uname']) || $_GET['uname']=="" ){
echo "请输入用户名"
return
}
$uname= $_GET['uname']
$sql="select tel from `yonghubiao` where name='$uname' top 1 "
$rs=$mysqli->query($sql)
$row = $rs->fetch_array(MYSQL_ASSOC)
echo $row['tel']
?>
引入文件 jq
一看你就是刚学习的菜鸟,没必要写两个sql语句,$sql = 'select user_id,user_name form user_list'查询出来赋值给变量$user然后遍历$userforeach($user as $value){
echo '<option value="'.$value['user_id'].'">'.$value['user_name'].'</option>'
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)