I need to create a table where it includes a user’s time duration on how much time he stays on a certain page… what data type should I use? should it be timestamp or datetime or time?
That is quite hard to do. First, you should use datetime. You can control that field better than timestamp.
Next, you need to lock in the time zone to ensure the time is always in the same time zone.
Then, you would need to alter the time each time the user changes pages. To do that, you would need
to have a header that is used in every page that marks the time the page was switched to. This is fairly easy to do. Just include a header.php file at the top of every page. Then, in that page, enter the log info for that user and that page. Note that this could end up with a huge log file if he goes back and forth on the pages often. (That depends on what kind of pages you are talking about.) Are you attempting to track this for a sales reason? It can be done, but, all of these things need to be addressed.
Hope this helps!
it is just an assignment of creating tables…yeah you’re explanation is too advanced already… lol
Well, if it is an assignment, they just want you to tell them how long they took to answer a question or in other words press a button. To do that, you save the time in a temporary variable and then when they press the button, subtract the current time to see the difference. does that make sense?
Well, to do this in PHP is tricky. You need to place the time on the page somehow.
Then, you need to read that time when they press the submit button. It is tricky to do that. I can give you code to do it. But, this assignment does really make sense. Perhaps you can tell us how it was worded?
If you want to save a starting time and a finishing time in the database and then include a field with the difference, you can do that using the DateDiff() function. This will let you save the duration between two date/times. Not sure if that is what you are needing…
This is just part of what the assignment says:
We also want to capture information about which page the logged in users are viewing (e.g. page visited, when they visited, how long they stayed, IP address, name, etc).
Well, you can save all that info at the top of every page in a header. What I am saying is that you can add code to the top of every single page to save the data. But, it would be a log of some sort. So, you would need to create the log table, create the columns for each of the items being saved and then create code to place the info into the table. But, you really would not have the time they stayed on the page, just a timestamp of when they went to the page. When you displayed the report, you could show when they switched pages and that would give you the time they were on the page. Kind of a complicated process to handle. I am heading to bed, but, can help further tomorrow.
ok thanks for your help