dflow Posted February 14, 2009 Share Posted February 14, 2009 im building a checkin checkout system how would you approach this: a user logs on his time and date are recorded and is logged out then what i want is on the next login to update the last record with time and date when logged out how can i get the last record entered by userID? Quote Link to comment https://forums.phpfreaks.com/topic/145233-get-last-record-by-userid/ Share on other sites More sharing options...
premiso Posted February 14, 2009 Share Posted February 14, 2009 Sort the field by userid, date in DESC order via the SQL query. Quote Link to comment https://forums.phpfreaks.com/topic/145233-get-last-record-by-userid/#findComment-762379 Share on other sites More sharing options...
dflow Posted February 14, 2009 Author Share Posted February 14, 2009 so actually i need an if else in the login to see if the last record by the user was inserted Quote Link to comment https://forums.phpfreaks.com/topic/145233-get-last-record-by-userid/#findComment-762389 Share on other sites More sharing options...
printf Posted February 14, 2009 Share Posted February 14, 2009 If I am understanding you, use... INSERT INTO values ('','') ON DUPLICATE KEY UPDATE some_field = with_some_other_field; Quote Link to comment https://forums.phpfreaks.com/topic/145233-get-last-record-by-userid/#findComment-762405 Share on other sites More sharing options...
dflow Posted February 15, 2009 Author Share Posted February 15, 2009 yes thanks i have the query im trying to call but it isn't filtering the records table using the logged in username session variable: $username_RsLastRecord = "-1"; if (isset($_SESSION['login_Username'])) { $user_RsLastRecord = $_SESSION['login_Username']; } mysql_select_db($database_shifts, $shifts); $query_RsLastRecord = sprintf("SELECT * FROM records WHERE records.UserName=$username_RsLastRecord ORDER BY records.ShiftStartTimeStamp DESC", GetSQLValueString($username_RsLastRecord, "int")); $RsLastRecord = mysql_query($query_RsLastRecord, $shifts) or die(mysql_error()); $row_RsLastRecord = mysql_fetch_assoc($RsLastRecord); $totalRows_RsLastRecord = mysql_num_rows($RsLastRecord); Quote Link to comment https://forums.phpfreaks.com/topic/145233-get-last-record-by-userid/#findComment-762448 Share on other sites More sharing options...
dflow Posted February 15, 2009 Author Share Posted February 15, 2009 ok figured it out thx Quote Link to comment https://forums.phpfreaks.com/topic/145233-get-last-record-by-userid/#findComment-762451 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.