Jump to content

time issues


Go to solution Solved by Barand,

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/284271-time-issues/
Share on other sites

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?
Link to comment
https://forums.phpfreaks.com/topic/284271-time-issues/#findComment-1460086
Share on other sites

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')

Link to comment
https://forums.phpfreaks.com/topic/284271-time-issues/#findComment-1460596
Share on other sites

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.)

Link to comment
https://forums.phpfreaks.com/topic/284271-time-issues/#findComment-1460668
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.