对于我网站上的每个广告,我想要一个显示其查看次数的框(类似于此网站)。
如何获取广告的页面浏览量?有没有在 PHP 中执行此操作的函数?
Well, no there is no function that does this magically : you'll have to do a bit of work -- not that hard, though ;-)
There are two possible things you can count.
For the first one, number of times an ad is displayed, the basic idea is :
update ad_counters set counter = counter + 1 where ad_id = 123
123
being replaced by the identifier of your ad, of course
For the second one, number of times an ad is clicked, the basic idea is generally :
http://yoursite.com/ad.php?id=123
update ad_clicks_counter set counter = counter + 1 where ad_id = 123
In fact, this is precisely what's done on SO :
http://ads.stackoverflow.com/a.aspx?Task=Click&ZoneID=4&CampaignID=785&AdvertiserID=161&BannerID=1123&SiteID=1&RandomNumber=384213225&Keywords=php%2ccounter%2cx-user-highrep%2cx-user-registered
http://www.xpolog.com/home/solutions/landing.jsp
Of course, those two counters can be in the same table -- or even in the table in which you have the list of all ads :-)