Question

I am new to web programming. I want to maintain user statistic. For eg. i have a db_user tables which has id_user, username, password

I want to maintain a statistics of pages visited by guest.

I am thinking of creating a 'stat' table with following fields -

id_stat, id_user (0 if guest), pageviewed.

What is the best way to do this?

Also, if I want to update id_user in 'stat' table - what is the best way to do this - is it by storing id_user in session variable and updating the stat table (updating id_user to 0 if session(id_user) is not set) by reading that variable?

Was it helpful?

Solution

Yes table looks pretty good. I would suggest storing NULL in id_user field if user is guest. You can store id_stat in users session and as soon as user registers or logins you can update row in stats table reading id_stat from session and putting users id in id_user field.

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