php如何做浏览量,php+ajax实现的点击浏览量加1
下面就分享一段相對完整的能夠在實際應用中派上用場的代碼,此代碼是ajax結合php代碼實現的。
一.ajax代碼如下:
ajax實現瀏覽量點擊增加var xmlhttp=false;
function add(){
try{
xmlhttp= new XMLHttpRequest;
}
catch(e){
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open('GET','count.php?a=a',false);
xmlhttp.onreadystatechange=func;
xmlhttp.send(null);
}
function func(){
if(xmlhttp.readyState==4){
var msg=xmlhttp.responseText;
var tt=document.getElementById("num");
tt.innerHTML=msg;
}
}
當前頁面數據庫中訪問次數:
二.php代碼:
mysql_connect('localhost','root','');
mysql_selectdb('click');
$rs=mysql_query("UPDATE click SET num = num +1 WHERE name = '".$_GET['a']."'");
if(mysql_affected_rows()==1){
$rs=mysql_query("select * from click where name='".$_GET['a']."'");
$row=mysql_fetch_array($rs);
echo $row['num'];
}
?>
以上所述就是本文的全部內容了,希望大家能夠喜歡。
時間: 2015-04-13
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的php如何做浏览量,php+ajax实现的点击浏览量加1的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php cannot find libz
- 下一篇: oracle 用户创建角色,oracle