开发者

Mysql insert and update impressions with PHP

I want to record number of advertisement impressions and clicks per day in database. I'm using PHP to insert and update that data i开发者_运维技巧n mysql.

The script that display specific advertisement and store data in db looks like:

...count the number of rows in db with this advertisement ID ...
if ($total == "0") {
mysql_query("INSERT INTO impressions VALUES ('".$id."','1','0',NOW('')");
}else{
mysql_query("UPDATE impressions SET impressions=impressions+1 WHERE id=$id;
}

Table in mysql database:

   id  |   impressions  | clicks  |   date
   ------------------------------------------
    5  |      104       |   23    | 2010-06-23

Can I somehow use limit for the number of impressions per day?

For example if advertiser wants to limit impressions of his add to 5000 per day.

How can I do that?


If you want to put a limit of impression per day, you need to have a place to save that configuration from the advertiser. After that, you only needs to select the adds that is that current impression is inferior than the limit for the current day!

Other thing... you should read something about sql injection and how to prevent that.

I hope my answer help you in any way.

Regards

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜