Tejpal Posted April 9, 2016 Share Posted April 9, 2016 (edited) 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 April 9, 2016 by Tejpal Link to comment Share on other sites More sharing options...
justsomeguy Posted April 11, 2016 Share Posted April 11, 2016 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 More sharing options...
Tejpal Posted April 18, 2016 Author Share Posted April 18, 2016 (edited) field is date/time plese describe How i do PDO instead of the mysql extension Edited April 18, 2016 by Tejpal Link to comment Share on other sites More sharing options...
justsomeguy Posted April 18, 2016 Share Posted April 18, 2016 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now