Trium918 Posted May 6, 2007 Share Posted May 6, 2007 What are the steps that I will need in order to keep up with Users last visited and diplay it to their member page. Last Visited 5/6/2007 Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/ Share on other sites More sharing options...
skali Posted May 6, 2007 Share Posted May 6, 2007 1- You need to keep a field in your users table 2- when user logs into you website update this field with the timestamp of server at that moment 3- display this field where you want Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/#findComment-246757 Share on other sites More sharing options...
Trium918 Posted May 6, 2007 Author Share Posted May 6, 2007 When you say the user table are you refering to the database? Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/#findComment-246765 Share on other sites More sharing options...
Barand Posted May 6, 2007 Share Posted May 6, 2007 1- You need to keep a field in your users table 2- when user logs into you website update this field with the timestamp of server at that moment 3- display this field where you want Step 1a, before you update, save the existing value as $lastVisit, otherwise you be displaying the time of this visit Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/#findComment-246785 Share on other sites More sharing options...
Trium918 Posted May 6, 2007 Author Share Posted May 6, 2007 This is what I have so far, and what is wrong with it? Question: When would the lastVisit column update. During registeration or during login. If its during login the field is lefted blank at registeration. CREATE TABLE users (username varchar(30),password varchar(32), lastVisit TIMESTAMP NULL DEFAULT NULL); <?php $currentVisit = date(); mysql_query( "update users set lastVisit= '$currentVisit' where user_name = '$user_name'"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/#findComment-246804 Share on other sites More sharing options...
Trium918 Posted May 6, 2007 Author Share Posted May 6, 2007 Step 1a, before you update, save the existing value as $lastVisit, otherwise you be displaying the time of this visit When would this process take place? Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/#findComment-246831 Share on other sites More sharing options...
rcorlew Posted May 6, 2007 Share Posted May 6, 2007 What I do is to only track logins. You have to concate the the time of login into a mysql field using a common delimiter to separate time entries. When the time of login is checked you can simply manipulate the $row['login_time'] by exploding it into an array. $log_times = explode(",", $row['login_time']);//If you use a comma as the delimiter You could then count the array using: $log_check = count($log_times -1); Php starts arrays at position 0, this will get you current login Now you can use the exploded array along with the array count to display the current login, if you want to you can use other variables to get various logins by manipulating the math formula on $log_check: $last_log = "$log_times[$log_check]"; echo "$last_log"; I hope that gets you going in the right direction. Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/#findComment-246833 Share on other sites More sharing options...
Trium918 Posted May 6, 2007 Author Share Posted May 6, 2007 What I do is to only track logins. You have to concate the the time of login into a mysql field using a common delimiter to separate time entries. When the time of login is checked you can simply manipulate the $row['login_time'] by exploding it into an array. $log_times = explode(",", $row['login_time']);//If you use a comma as the delimiter You could then count the array using: $log_check = count($log_times -1); Php starts arrays at position 0, this will get you current login Now you can use the exploded array along with the array count to display the current login, if you want to you can use other variables to get various logins by manipulating the math formula on $log_check: $last_log = "$log_times[$log_check]"; echo "$last_log"; I hope that gets you going in the right direction. Where does $row['login_time']; get its value from? Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/#findComment-246846 Share on other sites More sharing options...
rcorlew Posted May 6, 2007 Share Posted May 6, 2007 That would be in the user table. You would have a field that would track their login times, I just used the name login_time to make it easier to follow. Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/#findComment-246850 Share on other sites More sharing options...
Trium918 Posted May 6, 2007 Author Share Posted May 6, 2007 That would be in the user table. You would have a field that would track their login times, I just used the name login_time to make it easier to follow. This would be the field in database correct? login_time TIMESTAMP NULL DEFAULT NULL Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/#findComment-246870 Share on other sites More sharing options...
rcorlew Posted May 7, 2007 Share Posted May 7, 2007 That looks correct. Here is what your query would look like: <?php $result = mysql_query("UPDATE users SET login_time = CONCAT(COALESCE(login_time, ''), ' , $time)"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/#findComment-246916 Share on other sites More sharing options...
Trium918 Posted May 7, 2007 Author Share Posted May 7, 2007 Correct me if I am wrong, but wouldn't the syntax be similar to the code below for saving the existing value as $lastVisit. Note: The database field is set as TIMESTAMP NULL DEFAULT NULL Also, I noticed that when I enter data during registeration the TIMESTAMP field auto updated time. Not sure if this is what I want. <?php $currentVisit = date(); mysql_query( "update users set lastVisit= '$currentVisit' where user_name = '$user_name'"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/#findComment-247259 Share on other sites More sharing options...
tauchai83 Posted May 7, 2007 Share Posted May 7, 2007 create a field for user-> Last Visit (datetime) NOT NULL default:0000-00-00 00:00:00 then: <?php $sql1="SELECT Last_visit FROM user WHERE user_id='$userid'"; $result1=mysql_query($sql1); $row=mysql_fetch_assoc($result1); $last=$row['Last_visit']; $_SESSION['last']=$last; //use the session variable to hold the previous last visit date. $sql="UPDATE user SET Last_visit=NOW() WHERE user_id='$userid'"; //now only update it $result=mysql_query($sql); ?> it should work well for you. Regards, chai Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/#findComment-247261 Share on other sites More sharing options...
Trium918 Posted May 7, 2007 Author Share Posted May 7, 2007 Thanks tauchai8! I got it working, but I would I get the date to display 5/07/2007 format? Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/#findComment-247283 Share on other sites More sharing options...
Trium918 Posted May 7, 2007 Author Share Posted May 7, 2007 Why doesn't DATE_FORMAT(date_column, '%m d% Y%') work in the code below? <?php $sql1="SELECT DATE_FORMAT(Last_visit, '%m %d %Y') FROM members_info WHERE user_name='$user_name'"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/#findComment-247299 Share on other sites More sharing options...
benjaminbeazy Posted May 7, 2007 Share Posted May 7, 2007 depends, if you're field is unix timestamp, try FROM_UNIXTIME(Last_vist, '%m %d %Y') Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/#findComment-247316 Share on other sites More sharing options...
Trium918 Posted May 7, 2007 Author Share Posted May 7, 2007 The data field is set as Datetime not NULL default'0000-00-00' Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/#findComment-247325 Share on other sites More sharing options...
Trium918 Posted May 7, 2007 Author Share Posted May 7, 2007 What am I doing wrong? I am looking for this format MMDDYYYY last_visit datetime not NULL default'0000-00-00' returns YYYYMMDDHHMMSS last_visit TIMESTAMP NULL DEFAULT NULL returns YYYYMMDDHHMMSS <?php $sql1="SELECT last_visit FROM users WHERE user_name='$user_name'"; $result1=mysql_query($sql1); $row=mysql_fetch_assoc($result1); $last=$row['last_visit']; $_SESSION['last']=$last; //use the session variable to hold the previous last visit date. $sql="UPDATE users SET last_visit=NOW() WHERE user_name='$user_name'"; //now only update it $result2=mysql_query($sql); ?> Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/#findComment-247453 Share on other sites More sharing options...
Trium918 Posted May 7, 2007 Author Share Posted May 7, 2007 Were are them PHP Gurus? Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/#findComment-247598 Share on other sites More sharing options...
Trium918 Posted May 8, 2007 Author Share Posted May 8, 2007 Can anyone explain to me what is it that I am doing wrong. I an trying to get the last visit to display as 5/8/2007. Currently, I'm getting the output 20070508155335. If there are any question that will help you in guiding me, please ask! Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/#findComment-248404 Share on other sites More sharing options...
Barand Posted May 8, 2007 Share Posted May 8, 2007 <?php $d = '20070508155335'; echo date ('n/d/Y', strtotime($d)); //--> 5/08/2007 ?> Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/#findComment-248413 Share on other sites More sharing options...
Trium918 Posted May 8, 2007 Author Share Posted May 8, 2007 <?php $d = '20070508155335'; echo date ('n/d/Y', strtotime($d)); //--> 5/08/2007 ?> Shouldn't $d= what ever date is being pulled from the database, just asking? Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/#findComment-248417 Share on other sites More sharing options...
per1os Posted May 8, 2007 Share Posted May 8, 2007 Wow, yes $d should be whatever date you want to be converted to a specific format. strtotime is a wonderful function, glad the php coders included it. Makes date conversion a ton easier! Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/#findComment-248419 Share on other sites More sharing options...
Trium918 Posted May 8, 2007 Author Share Posted May 8, 2007 <?php $d = '20070508155335'; echo date ('n/d/Y', strtotime($d)); //--> 5/08/2007 ?> I just tried this as a test and I got a blank screen! Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/#findComment-248422 Share on other sites More sharing options...
Trium918 Posted May 8, 2007 Author Share Posted May 8, 2007 <?php $d = '20070508155335'; echo date ('n/d/Y', strtotime($d)); //--> 5/08/2007 ?> I just tried this as a test and I got a blank screen! The problem was the time added at the end 155335. Is there a way to do away with this? Quote Link to comment https://forums.phpfreaks.com/topic/50264-solved-last-visited-weigh-in-please/#findComment-248431 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.