Jump to content

how to show online user


Tejpal

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 comment
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 comment
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 comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...