nightkarnation Posted April 12, 2011 Share Posted April 12, 2011 Hey Guys. I have the following problem on mysql database: With php using $time = time(); I receive for example: 1302638294 I need something more accurate than this because sometimes I receive on my DB the same value (2 times) and it generates some conflicts due to the fact I am using this information to know which user sent some information, first, second, etc... Does anyone have any suggestions on how I can solve this problem? Thanks a lot in advance! Cheers. Quote Link to comment https://forums.phpfreaks.com/topic/233525-time-time-need-something-better-with-microseconds/ Share on other sites More sharing options...
requinix Posted April 12, 2011 Share Posted April 12, 2011 Try this. Quote Link to comment https://forums.phpfreaks.com/topic/233525-time-time-need-something-better-with-microseconds/#findComment-1200784 Share on other sites More sharing options...
nightkarnation Posted April 12, 2011 Author Share Posted April 12, 2011 Yes I already tried that. Thanks a lot. The problem is that for example on my DB...the value from $time = time(); is being stored on a field called Raw_Time with Data Type int(32) And when I use $time = microtime(); I get on DB a 0 value... And I need the int type on the Raw_Time because I need to: ORDER BY `CLICKING_HISTORY`.`Raw_Time` DESC LIMIT 0 , 10 I apologize for not explaining this before. Looking forward for any suggestions or ideas. Thanks a lot in advance! Quote Link to comment https://forums.phpfreaks.com/topic/233525-time-time-need-something-better-with-microseconds/#findComment-1200790 Share on other sites More sharing options...
dcro2 Posted April 12, 2011 Share Posted April 12, 2011 Why don't you change the Raw_Time datatype to FLOAT and use microtime(true) since it returns a float? Quote Link to comment https://forums.phpfreaks.com/topic/233525-time-time-need-something-better-with-microseconds/#findComment-1200797 Share on other sites More sharing options...
markjoe Posted April 12, 2011 Share Posted April 12, 2011 So you need to store a microtime in an Int field? microtime() returns a string or float. http://us3.php.net/manual/en/function.microtime.php how about microtime(true)*10000 ?? Quote Link to comment https://forums.phpfreaks.com/topic/233525-time-time-need-something-better-with-microseconds/#findComment-1200798 Share on other sites More sharing options...
nightkarnation Posted April 12, 2011 Author Share Posted April 12, 2011 Thanks a lot for all your help! Markjoe I tried your code and I get a 4 value number... And based on that I tried: $time = time(); //for Raw_Time $timeSec = microtime(true)*10000; $time = $time . $timeSec; But instead of adding the value with 4 numbers after the time, I think its being added to the time result. Any ideas on how I can format this better than what I am doing? Quote Link to comment https://forums.phpfreaks.com/topic/233525-time-time-need-something-better-with-microseconds/#findComment-1200813 Share on other sites More sharing options...
nightkarnation Posted April 12, 2011 Author Share Posted April 12, 2011 Anyone please? Quote Link to comment https://forums.phpfreaks.com/topic/233525-time-time-need-something-better-with-microseconds/#findComment-1200836 Share on other sites More sharing options...
dcro2 Posted April 12, 2011 Share Posted April 12, 2011 I think he meant for you to use it alone, not to add it to time(). $time = microtime(true)*10000; Quote Link to comment https://forums.phpfreaks.com/topic/233525-time-time-need-something-better-with-microseconds/#findComment-1200839 Share on other sites More sharing options...
Andy-H Posted April 12, 2011 Share Posted April 12, 2011 You could prefix the timestamp with the user's ID (primary key)? //pull some user data making sure you include userID $uniqueTime = $row['userID'] . time(); //insert data into appropriate table then to find the time //pull unique time $timeOfAction = time() - substr($row['uniqueTime'], 1); echo 'Action made ' . $timeOfAction . ' seconds ago.'; Quote Link to comment https://forums.phpfreaks.com/topic/233525-time-time-need-something-better-with-microseconds/#findComment-1200848 Share on other sites More sharing options...
markjoe Posted April 12, 2011 Share Posted April 12, 2011 Yes I meant to use it alone. microtime(true) * 10000 // 13026477307764 Quote Link to comment https://forums.phpfreaks.com/topic/233525-time-time-need-something-better-with-microseconds/#findComment-1200855 Share on other sites More sharing options...
nightkarnation Posted April 12, 2011 Author Share Posted April 12, 2011 Mark, Using it alone, I am getting: 2601.34 Could it be becuase I have php 4 instead of 5??? Thanks a lot! Quote Link to comment https://forums.phpfreaks.com/topic/233525-time-time-need-something-better-with-microseconds/#findComment-1200873 Share on other sites More sharing options...
markjoe Posted April 12, 2011 Share Posted April 12, 2011 php4????? yea maybe, I don't know it would do in php4 off the top of my head. why on earth would you be using php4? the get as float parameter was added in 5. best advice is to get the string value and chop it up to get the "unique" int you want and read this: http://us3.php.net/manual/en/function.microtime.php Quote Link to comment https://forums.phpfreaks.com/topic/233525-time-time-need-something-better-with-microseconds/#findComment-1200876 Share on other sites More sharing options...
dcro2 Posted April 13, 2011 Share Posted April 13, 2011 Just do this instead: list($u, $s) = explode(' ', microtime()); $time = bcadd($u, $s, 7)*10000; (not taking credit, I did find it posted by someone on the microtime manual page) Quote Link to comment https://forums.phpfreaks.com/topic/233525-time-time-need-something-better-with-microseconds/#findComment-1200924 Share on other sites More sharing options...
nightkarnation Posted April 13, 2011 Author Share Posted April 13, 2011 Awesome! Thanks a lot to all of you for your kind help! I changed to php5 and now works great. Quote Link to comment https://forums.phpfreaks.com/topic/233525-time-time-need-something-better-with-microseconds/#findComment-1201206 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.