For each ad on my site, I would like a box that shows the number of views it has (similar to this site).
How would I capture the number of page views an ad has? Is there a function that does this in PHP?
For each ad on my site, I would like a box that shows the number of views it has (similar to this site).
How would I capture the number of page views an ad has? Is there a function that does this in 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 :-)