先来创建数据库.
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 ;
数据创建好了我们就开始写程序了.数据连接我不不写了,
<?php
require_once("......省了");
$ad_id =get_value('ad_id','');这里下面有讲
if(is_numeric( $ad_id ) ){
$ad_select="select ad_id,ad_url from ad_count where ad_id='$ad_id' limit 1";
$ad_update="update ad_count set ad_hit=ad_hit+1 where ad_id='$ad_id' limit 1";
$ad_result=mysql_query($ad_select) or die('id error');
if( mysql_num_rows( $ad_result) ){
mysql_query($ad_update);
$ad_rs=mysql_fetch_array($ad_result);
header("location:".$ad_rs['ad_url']);
mysql_free_result($ad_rs);
}
}
function htmltohtml($str){
$temp =str_replace(chr(13),'<br/>',$str);
$temp =str_replace('<','<',$str);
$temp =str_replace('>','>',$str);
$temp =addslashes($str);
return $temp;
}
function get_value($value,$para){
return htmltohtml(empty($para)?(isset($_get[$value])?$_get[$value]:''):(isset($_post[$value])?$_post[$value]:''));
}
然后我们再在要显示广告的地方如下写.
706f204fa55b23722b9b3cfdf241a1d7d7ad26efe115e551ee002eaeafc7f0275db79b134e9f6b82c0b36e0489ee08ed
就完了
以上就是实现广告点击率统计php代码的详细内容。