php+ajax实现的点击浏览量加1

yipeiwu_com6年前PHP代码库

下面就分享一段相对完整的能够在实际应用中派上用场的代码,此代码是ajax结合php代码实现的。

一.ajax代码如下:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<title>ajax实现浏览量点击增加</title>
<script type="text/javascript">
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;
 }
}
</script>
</head>
<body>
当前页面数据库中访问次数:<div id='num'></div>
<input type="button" value="增加次数" >
</body>
</html>

二.php代码:

<?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'];
 }
?>

以上所述就是本文的全部内容了,希望大家能够喜欢。

相关文章

php 友好URL的实现(吐血推荐)

友好URL的实现(吐血推荐) 大家经常看到别的站的URL是这样的吧? http://www.xxx.com/module/show/action/list/page/7 或者 http:...

解析如何在PHP下载文件名中解决乱码的问题

通过把Content-Type设置为application/octet-stream,可以把动态生成的内容当作文件来下载,相信这个大家都会。那么用Content-Disposition设...

php+ajax实现无刷新分页的方法

本文实例讲述了php+ajax实现无刷新分页的方法。分享给大家供大家参考。具体实现方法如下: 这是一款基于原生态的php +js +ajax 的分页程序实例,我们详细的从数据库创建到js...

PHP 反向排序和随机排序代码

array_reverse()函数与shuffle()函数介绍 array_reverse() array array_reverse(array)array_reverse()函数传入...

php sprintf()函数让你的sql操作更安全

$bookSQL=sprintf("UPDATE book SET pass=%s WHERE id=%d",   ...