Home > Backend Development > PHP Tutorial > Implement advertising click rate statistics php code

Implement advertising click rate statistics php code

小云云
Release: 2023-03-20 11:22:02
Original
2178 people have browsed it

Let’s create the database first.


CREATE TABLE IF NOT EXISTS `ad_count` (
`ad_id` int(8) NOT NULL auto_increment,
`ad_hit` int(8) NOT NULL default '0',
`ad_name` varchar(200) character set gb2312 default NULL,
`ad_datetime` datetime default NULL,
`ad_qq` varchar(15) character set gb2312 default NULL,
`ad_url` varchar(900) character set gb2312 NOT NULL,
`ad_price` int(8) NOT NULL,
PRIMARY KEY (`ad_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
Copy after login

After the data is created, we start writing the program. I will not write the data connection,


<?php
 require_once("......省了");
 $ad_id =get_value(&#39;ad_id&#39;,&#39;&#39;);这里下面有讲
 if(is_numeric( $ad_id ) ){
 
  $ad_select="select ad_id,ad_url from ad_count where ad_id=&#39;$ad_id&#39; limit 1";  
  $ad_update="Update ad_count set ad_hit=ad_hit+1 where ad_id=&#39;$ad_id&#39; limit 1";
  
  $ad_result=mysql_query($ad_select) or die(&#39;id error&#39;);
  
   if( mysql_num_rows( $ad_result) ){   
    mysql_query($ad_update);    
    $ad_rs=mysql_fetch_array($ad_result);    
    header("location:".$ad_rs[&#39;ad_url&#39;]);    
    mysql_free_result($ad_rs);       
   }
 }

function htmltohtml($Str){
 $temp =str_replace(chr(13),&#39;<br/>&#39;,$Str);
 $temp =str_replace(&#39;<&#39;,&#39;<&#39;,$Str);
 $temp =str_replace(&#39;>&#39;,&#39;>&#39;,$Str);
 $temp =addslashes($Str);
 return $temp;
 }
 function get_value($value,$para){ 
 return htmltohtml(empty($para)?(isset($_GET[$value])?$_GET[$value]:&#39;&#39;):(isset($_POST[$value])?$_POST[$value]:&#39;&#39;));
 }
Copy after login

Then we write as follows where we want to display ads.

< ;img src=/ad_a/ad2.gif border=0 />

That’s it

The above is the detailed content of Implement advertising click rate statistics php code. For more information, please follow other related articles on the PHP Chinese website!

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