Question

I want to put a hit counter or visits to display for my website http://www.deerpages.co on every dynamic pages. I'm using Php and MySQL. But, I'm thinking of once I've put every tracking in per row inserted, then that table will be full soon.

Is there any external ways we can do this? I mean, like Google Analytics or Alexa type of trackings? and can be able to display them?

Any help would be appreciated.

Thanks a lot!

Was it helpful?

Solution

When you put a page counter on content, you change the value of the counter in your database, not insert a new row for it each time.

Assuming your table looks something like this:

contentTable
+------+---------+
| ID   | Counter |
|------|---------|
| 1    | 35      |
| 2    | 54      |
+------+---------+

You can update the row with ID of 1 like this:

update contentTable set Counter=Counter+1 where ID=1;

Assuming that you link each page to an ID in the database. You can also easily keep all your content in the same database table.

Edit: If you want to store other data about each visitor, then make a separate hitCounter table along the following lines:

    CounterTable
+----+---------+----------+---------|
| ID | Counter | HTTP_REf | Country |
|----+---------+----------+---------|
| 1  | 46      | SomeData | USA     |
| 2  | 28      | Data2    | Aus     |
+----+---------+----------+---------+

And update the data as required based on the users individual data columnsm such as: insert into counterTable (ID, Counter, HTTP_Ref, Country) values (null, 1, '".$HTTP_REF."', '".$country."') On Duplicate Key update set counter=counter+1;

(Assuming Keys of ID, HTTP_Ref and Country)

Having said that, I would suggest either looking at using some space on the database (really, you will need a LOT of hits to "fill up the tables" as such) or maybe simply split the basic counter with a stats table that lists Country, Referrer and the like into different tables.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top