To create the database first.
CREATE TABLE IF not EXISTS ' ad_count ' (' ad_id ' int (8) is not NULL auto_increment, ' ad_hit ' int (8) is not null default ' 0 ', ' Ad_nam E ' varchar (character) set gb2312 default null, ' Ad_datetime ' datetime default NULL, ' AD_QQ ' varchar (character set GB) 2312 default NULL, ' Ad_url ' varchar (character set gb2312 not NULL, ' ad_price ' int (8) Not null,primary KEY (' ad_id ')) EN Gine=innodb DEFAULT charset=latin1 auto_increment=4;
When the data is created, we start to write the program. Data connection I'm not going to write.
<?php require_once ("... Save "); $ad _id =get_value (' ad_id ', '); here is the 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), ' <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]: "); }
Then we'll write the following where we want to show the ad.
<a href=/cp/ad_count.php?ad_id=2 target=_blank></a>
I'm done.