Sorry for not getting back to you about my idea. What I meant was, you store the timestamp for each user's last activity in the database. Then any time you want to check if someone is "active" you grab the timestamp and make the comparison.
You can also get a list of "active" user by doing (psuedocode) "SELECT * FROM user_activity WHERE timestamp>TIME()-60*5"
All you need to do for this is update the user's "last activity" timestamp every time they request a page, and you'll be laughing.
If you want it to be more accurate you can use AJAX to send a request to the server every 4 mins to tell the server that the user still has the webpage open in his/her browser.
Hope that helped. (I'm not saying the other way won't work either..)
humbug
Junior Poster in Training
93 posts since Oct 2005
Reputation Points: 20
Solved Threads: 13
Skill Endorsements: 0
Holy Moley, you'll hate your self for this :P You forgot a crucial line: mysql_query($sql); which should go on line 16. As your code stands, it doesn't execute the new SQL command, just sets the $sql variable.
Regarding the VALUE syntax, VALUE and VALUES are interchangeable.
humbug
Junior Poster in Training
93 posts since Oct 2005
Reputation Points: 20
Solved Threads: 13
Skill Endorsements: 0
The easiest way to do this would be to set a column "lastactivity" to the current time every time the user loads any of your pages (just build it into your authentication script). You can then classify someone as "online" if they have been active in the past 5 mins.
Hope that's close enough to what you're after.
humbug
Junior Poster in Training
93 posts since Oct 2005
Reputation Points: 20
Solved Threads: 13
Skill Endorsements: 0
Perhaps I've misunderstood the question, and the two previous posters used regular expressions but I would normally test a date with something like the following:
function is_date($value) {
// If the value of the field is empty, immediately return false.
if (empty($value)) { return FALSE; }
// Attach the exploded values to variables.
list($day, $month, $year) = explode("/", $value);
// Check those variables in the checkdate function. If it's valid, the function returns true.
return checkdate($month, $day, $year);
}
This is a great method for the date. If you wanted to you could even return "$year - $month - $day"; if it is a valid date or FALSE if it isn't seeing as you already have the variables set.
As for the time, I would probably take the input as a string and use one of the regular expression checks above to see if it consists of 4 numbers, then typecast it to an integer and check if ($time_num >= 900 && $time_num <= 1700) { echo "time is valid"; }
humbug
Junior Poster in Training
93 posts since Oct 2005
Reputation Points: 20
Solved Threads: 13
Skill Endorsements: 0
Check out this and look into getting the entire file into a variable with "\n\r" (linefeed and carriage return) separating each line of text. Alternatively write each line to the printer with it's own call of printer_write() . The latter may be easier as you usually read data from a file line by line. It may also be torture for the printer and rather slow, I don't know how printer_write() works.
For this same reason I don't know how a new line command should be issued. Try the following and see what happens: printer_write($handle, "Text \nTo print"); This is the most likely solution and sould print:
Text
To print
printer_write($handle, "Text \n\rTo print"); This may be needed instead to give the above result.
Also try:
printer_write($handle, "Line 1");
printer_write($handle, "Line 2");
printer_write($handle, "Line 3");
printer_write($handle, "Line 4");
And see how it reacts and if it works. If your still can't get around it then tell me how each of those tests went.
humbug
Junior Poster in Training
93 posts since Oct 2005
Reputation Points: 20
Solved Threads: 13
Skill Endorsements: 0
Why the $result = mysql_query($query); on the fourth last line? You don't need the $result = on that line as the mysql_query will return TRUE on success. You are then treating this as a MySQL result resource in mysql_fetch_array($result) (because the expression in the why loop is executed every time the while loop tries to run).
See http://au.php.net/manual/en/function.mysql-query.php
You should get rid of the $result = assignment (or use a different variable name if it is needed) and it should work.
humbug
Junior Poster in Training
93 posts since Oct 2005
Reputation Points: 20
Solved Threads: 13
Skill Endorsements: 0