一.ajax代码如下:
<!DOCTYPEhtml>
<html>
<head>
<metacharset="utf-8">
<title>ajax实现浏览量点击增加</title>
<scripttype="text/javascript">
varxmlhttp=false;
functionadd(){
try{
xmlhttp=newXMLHttpRequest;
}
catch(e){
xmlhttp=newActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open('GET','count.php?a=a',false);
xmlhttp.onreadystatechange=func;
xmlhttp.send(null);
}
functionfunc(){
if(xmlhttp.readyState==4){
varmsg=xmlhttp.responseText;
vartt=document.getElementById("num");
tt.innerHTML=msg;
}
}
</script>
</head>
<body>
当前页面数据库中访问次数:<divid='num'></div>
<inputtype="button"value="增加次数">
</body>
</html>
二.php代码:
<?php
mysql_connect('localhost','root','');
mysql_selectdb('click');
$rs=mysql_query("UPDATEclickSETnum=num+1WHEREname='".$_GET['a']."'");
if(mysql_affected_rows()==1){
$rs=mysql_query("select*fromclickwherename='".$_GET['a']."'");
$row=mysql_fetch_array($rs);
echo$row['num'];
}
?>
|