|
So at the moment you have 1 table e.g. clicks with fields URL, creation date and IP? And from it you want to create a report of form, e.g. URL - number of distinct IPs during the last 24 hours?
If all the above is true, I'd recommend you to change the layout of this table and add one more table named e.g. links. The links table should have following fields:
1. ID int not null auto_increment, primary key
2. Site name
3. Site URL
4. Anything else, like 'open in new window', 'make it bold', etc
Next you replace the URL in your current table with site_id from the newly created one. This will perform better not only on insert but also on select.
Now to get the report you should do:
1. select * from links
2. foreach ($links as $l) $links_indexed[$l->id] = $l;
3. select site_id, count(ip) as clicks from clicks group by site_id order by clicks desc where date_sub(now(), interval 24 hour) > added
4. foreach ($clicks as $c) {
$links_indexed[$c->site_id]->clicks = $c->clicks;
}
Something like that, yes. This will perform quite fine and can be easily optimized further by adding file cache.
|