Add 1 to the number of click views implemented by php ajax, and the number of ajax views_PHP tutorial

WBOY
Release: 2016-07-13 09:56:46
Original
1004 people have browsed it

The number of click views implemented by php ajax is increased by 1, and the number of ajax views

The following is a relatively complete code that can be used in practical applications. This code is ajax Implemented in combination with php code.

1.ajax code is as follows:

<!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&#63;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>
Copy after login

2.php code:

<&#63;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'];
 }
&#63;>
Copy after login

The above is the entire content of this article, I hope you all like it.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/985283.htmlTechArticlephp ajax achieves click views plus 1, ajax views below I will share a relatively complete paragraph that can be applied in practice The code that comes in handy, this code is implemented by ajax combined with php code. ...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template