Forum Moderators: open
I tend to put complex calculation like this into the database itself and save it as a query, I am talking Access here, as it runs faster within the database rather than outside and is less sever intensive. Then I simply grab the totals via a simpler SQL statement. It may only be a small difference per se but as the number of page hits grows it can mean a considerable saving overall.
Onya
Woz
All newer implementations of SQL use variations of B+ trees which have basically been proven to be the fastest algorithms for organization of large amounts of data. So basically, if SQL can do it with a query, you can't write PHP code to do it any faster(speaking in terms of big O, you might possibly be able to save a few clock cycles if you are really good, but nothing significant). In the best case, you'll waste alot of time studying algorithms to do it 'as good' as SQL does.