Jayden_Blade Posted November 25, 2013 Share Posted November 25, 2013 I am trying to show active users with in the last 5 mins. <?php error_reporting(E_ALL); include ("/home/jayden1/database_access/dblogincheck.php"); $d=date('c',time()-5*60);//last 5 minutes echo $d; $q=mysql_query("SELECT `username` FROM `navigate` WHERE `time` >= '$d'") or die ("query failed to find".mysql_error()); echo $q; if(mysql_num_rows($q)>0){ print "<ul>"; echo $q; while($users=mysql_fetch_array($q)){ print "<li>{$users[0]}</li>"; } print "</ul>"; echo $users; } ?> no errors just wont display. I know the time in my db updates every time a pages is loaded Quote Link to comment https://forums.phpfreaks.com/topic/284271-time-issues/ Share on other sites More sharing options...
requinix Posted November 25, 2013 Share Posted November 25, 2013 If the "time" field is an integer then don't use date(). If it's a DATETIME field then you should be using "Y-m-d H:i:s" format for the date. $d=date('Y-m-d H:i:s', time() - 5 * 60);If that's still not working, what are the values of some of the rows from the navigate table you expected it to find? Quote Link to comment https://forums.phpfreaks.com/topic/284271-time-issues/#findComment-1460086 Share on other sites More sharing options...
Jayden_Blade Posted November 29, 2013 Author Share Posted November 29, 2013 doesn't work. i am trying to get a list of active users. Last 5 mins login or refresh. Quote Link to comment https://forums.phpfreaks.com/topic/284271-time-issues/#findComment-1460594 Share on other sites More sharing options...
aysiu Posted November 29, 2013 Share Posted November 29, 2013 I think the issue is in the time formats. You're using c for the PHP date format, which will output something like 2004-02-12T15:19:21+00:00, but you're then comparing that string to a time stored in MySQL, which, if it's time format would be something like 15:19:21. For this sort of thing, I'd recommend creating an integer field in MySQL that's ten-digits long and have that store a UNIX timestamp. Then compare that to a strtotime in PHP of now minus five minutes: strtotime('-5 minutes') Quote Link to comment https://forums.phpfreaks.com/topic/284271-time-issues/#findComment-1460596 Share on other sites More sharing options...
Jayden_Blade Posted November 29, 2013 Author Share Posted November 29, 2013 In my table it is 2013-11-29 15:20:21 Quote Link to comment https://forums.phpfreaks.com/topic/284271-time-issues/#findComment-1460666 Share on other sites More sharing options...
mac_gyver Posted November 29, 2013 Share Posted November 29, 2013 are you sure you have rows in your navigate table with values like that? your date('c') value, when being inserted into the table (i.e. your previous thread) is either producing a mysql error for an invalid date/time value (mysql in strict mode) or is inserting an all zero date/time (mysql not in strict mode.) Quote Link to comment https://forums.phpfreaks.com/topic/284271-time-issues/#findComment-1460668 Share on other sites More sharing options...
Jayden_Blade Posted November 29, 2013 Author Share Posted November 29, 2013 its posting via now() Quote Link to comment https://forums.phpfreaks.com/topic/284271-time-issues/#findComment-1460671 Share on other sites More sharing options...
Jayden_Blade Posted November 29, 2013 Author Share Posted November 29, 2013 (edited) two different things (i.e. your previous thread) Edited November 29, 2013 by Jayden_Blade Quote Link to comment https://forums.phpfreaks.com/topic/284271-time-issues/#findComment-1460672 Share on other sites More sharing options...
jcbones Posted November 30, 2013 Share Posted November 30, 2013 (edited) If it is posting via now(), SELECT `username` FROM `navigate` WHERE `time` BETWEEN NOW() AND DATE_SUB(NOW(),INTERVAL 5 MINUTE) Just keep it in MySQL, and let her do the work. Edited November 30, 2013 by jcbones Quote Link to comment https://forums.phpfreaks.com/topic/284271-time-issues/#findComment-1460674 Share on other sites More sharing options...
Solution Barand Posted November 30, 2013 Solution Share Posted November 30, 2013 you need the earlier time first with a BETWEEN SELECT `username` FROM `navigate` WHERE `time` BETWEEN NOW() - INTERVAL 5 MINUTE AND NOW() Quote Link to comment https://forums.phpfreaks.com/topic/284271-time-issues/#findComment-1460676 Share on other sites More sharing options...
Jayden_Blade Posted November 30, 2013 Author Share Posted November 30, 2013 Sweet thanks! One more question with the same code..... how can i make $users a link? while($users=mysql_fetch_array($q)) Quote Link to comment https://forums.phpfreaks.com/topic/284271-time-issues/#findComment-1460679 Share on other sites More sharing options...
Jayden_Blade Posted November 30, 2013 Author Share Posted November 30, 2013 print "<li>{$users[0]}</li>"; ^ | Make that $users into a link not the other lol Quote Link to comment https://forums.phpfreaks.com/topic/284271-time-issues/#findComment-1460680 Share on other sites More sharing options...
Barand Posted November 30, 2013 Share Posted November 30, 2013 The usual way is to display the name but pass the unique id in the link, so echo "<li><a href='userpage.php?id={$user['id']}'>{$user['name']}</a></li>"; Quote Link to comment https://forums.phpfreaks.com/topic/284271-time-issues/#findComment-1460736 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.