Reputation: 4578
Here's my scenario.
1) I have a website which displays a banner ad
2) The banner ad will be displayed by a php file, bannerviewer.php.
3) The main page (index.php) will call the bannerviewer.php, like this
$promotion = "bannerviewer.php?ad_id=1&user_id=123";
echo $promotion;
4) the file bannerviewer.php will be able to store in database the id of the called ad (ad_id) and the viewer's id (user_id)
5) my problem is, what's the best practice to store the ad_id and user_id for such scenario? should I just run (i) "insert into analytics_table (ad_id) values (?)" command everytime the page bannerviewer.php is called, or (ii) "update analytics_table set pageviews=? where ad_id=?" with new data?
6) from what I see, the problem with approach (i) is, the database can easily get very large if the websites gains much hits. later I need to create some sort of report using the data in the table, so wouldn't this pose a problem? and the problem with approach (ii) is, to run the update command with latest data, I need to run select command first to get the previous data and increment the pageview info manually, which will consume more resources than the first approach (but the table size would be more reasonable).
hope u guys understand my question
thanks
Upvotes: 0
Views: 60
Reputation: 102
In (ii), you can update the pageviews with a single update sql:
UPDATE `analytics_table` SET `pageviews` = `pageviews` + 1 where ad_id = x
if you just count the pageviews, you'd better choose (ii), if you want get all details of every visit, you need another table to store it.
Upvotes: 1