Jump to content

how to show online user


Recommended Posts

I want to show online user in my project where 2 field in mysql table

1st onlinestoptime and 2nd onlinestarttime

when user login and online show in mysql onlinestoptime value null

and onlinestarttime value is timestamp (show time when user online like 09/04/2016 12:01:02)

my code here but not working

so How i done and show online user

<?

date_default_timezone_set('Asia/Kolkata');
$dt=date('Y-m-d h:i:s ');
echo $sql="SELECT *FROM mytable where onlinestoptime like '%%' and onlinestarttime<'$dt' ";
$val=mysql_query($sql);
?>
Thanks in advance
Edited by Tejpal
Link to post
Share on other sites

If onlinestoptime is null then check for null, not a wildcard matching any string.

 

What is the data type of the onlinestarttime field, is it a text type like varchar or is a date/time type?

 

You really need to use prepared statements with PDO instead of the mysql extension, your code will not work in PHP 7.

Link to post
Share on other sites

There's a PDO tutorial here, there are many others online if you do a search:

 

http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers

 

It looks like your query has a syntax error, but you're not checking for errors. With PDO you should set it up to throw an exception when there's an error so you can see them.

Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...