Re: [PHP-DB] newbie - problems with Select and timestamp(14) calculation
(NOW()+0) Not sure what the +0 achieves?? Try with just NOW(). Cheers. Russ On Thu, 18 Oct 2001 11:41:14 +0100 p.whiter [EMAIL PROTECTED] wrote: Hi I am trying to set-up a type of anti-flood block on one of my forms, the way I am doing this is that when the first submission is made I log various details into a user_log table including IP no and a Timestamp (14) column called log_time. Now if the button is clicked again the php script will run the following query: SELECT user_ip FROM clinic_log WHERE user_ip = '$pw_userIP' AND (((NOW()+0) - clinic_log.log_time ) 300) What I am (trying) doing here is to check the users IP ($pw_userIP) against the user_ip column in the database and if it matches then check to see whether it has been there for less than 300 seconds. I have just spent the last couple of hours trying to get this working..it doesn't want to know. It keeps finding the matching IP and disregarding the time calculation.. Thanks for any help. Paul -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] #---# Believe nothing - consider everything Russ Michell Anglia Polytechnic University Webteam Room 1C 'The Eastings' East Road, Cambridge e: [EMAIL PROTECTED] w: www.apu.ac.uk/webteam www.theruss.com #---# -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] newbie - problems with Select and timestamp(14) calculation
Hi Thanks for your reply, I have tried this using NOW() and NOW()+0, there is no difference, I think I have narrowed the problem down to the time part of the timestamp being disregarded, as I have written the query below it is making the calculation using days rather than seconds.. This should really be a rather simple query to achieve, but it is turning into a big headache. Thanks again Paul - Original Message - From: Russ Michell [EMAIL PROTECTED] To: p.whiter [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Thursday, October 18, 2001 12:24 PM Subject: Re: [PHP-DB] newbie - problems with Select and timestamp(14) calculation : (NOW()+0) : Not sure what the +0 achieves?? Try with just NOW(). : : Cheers. : Russ : : On Thu, 18 Oct 2001 11:41:14 +0100 p.whiter [EMAIL PROTECTED] wrote: : : Hi : I am trying to set-up a type of anti-flood block on one of my forms, the way : I am doing this is that when the first submission is made I log various : details into a user_log table including IP no and a Timestamp (14) column : called log_time. Now if the button is clicked again the php script will run : the following query: : : SELECT user_ip FROM clinic_log WHERE user_ip = '$pw_userIP' AND : (((NOW()+0) - clinic_log.log_time ) 300) : : What I am (trying) doing here is to check the users IP ($pw_userIP) against : the user_ip column in the database and if it matches then check to see : whether it has been there for less than 300 seconds. : : I have just spent the last couple of hours trying to get this : working..it doesn't want to know. It keeps finding the matching IP and : disregarding the time calculation.. : : Thanks for any help. : Paul -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] newbie - problems with Select and timestamp(14) calculation
Take a good look at the manual page, it helped me out a bunch of times: http://www.mysql.com/doc/D/a/Date_and_time_functions.html Good luck. Russ On Thu, 18 Oct 2001 14:02:34 +0100 p.whiter [EMAIL PROTECTED] wrote: Hi Thanks for your reply, I have tried this using NOW() and NOW()+0, there is no difference, I think I have narrowed the problem down to the time part of the timestamp being disregarded, as I have written the query below it is making the calculation using days rather than seconds.. This should really be a rather simple query to achieve, but it is turning into a big headache. Thanks again Paul - Original Message - From: Russ Michell [EMAIL PROTECTED] To: p.whiter [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Thursday, October 18, 2001 12:24 PM Subject: Re: [PHP-DB] newbie - problems with Select and timestamp(14) calculation : (NOW()+0) : Not sure what the +0 achieves?? Try with just NOW(). : : Cheers. : Russ : : On Thu, 18 Oct 2001 11:41:14 +0100 p.whiter [EMAIL PROTECTED] wrote: : : Hi : I am trying to set-up a type of anti-flood block on one of my forms, the way : I am doing this is that when the first submission is made I log various : details into a user_log table including IP no and a Timestamp (14) column : called log_time. Now if the button is clicked again the php script will run : the following query: : : SELECT user_ip FROM clinic_log WHERE user_ip = '$pw_userIP' AND : (((NOW()+0) - clinic_log.log_time ) 300) : : What I am (trying) doing here is to check the users IP ($pw_userIP) against : the user_ip column in the database and if it matches then check to see : whether it has been there for less than 300 seconds. : : I have just spent the last couple of hours trying to get this : working..it doesn't want to know. It keeps finding the matching IP and : disregarding the time calculation.. : : Thanks for any help. : Paul -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] #---# Believe nothing - consider everything Russ Michell Anglia Polytechnic University Webteam Room 1C 'The Eastings' East Road, Cambridge e: [EMAIL PROTECTED] w: www.apu.ac.uk/webteam www.theruss.com #---# -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] newbie - problems with Select and timestamp(14) calculation
On Thursday 18 October 2001 18:41 pm, p.whiter wrote: Hi I am trying to set-up a type of anti-flood block on one of my forms, the way I am doing this is that when the first submission is made I log various details into a user_log table including IP no and a Timestamp (14) column called log_time. Now if the button is clicked again the php script will run the following query: SELECT user_ip FROM clinic_log WHERE user_ip = '$pw_userIP' AND (((NOW()+0) - clinic_log.log_time ) 300) What I am (trying) doing here is to check the users IP ($pw_userIP) against the user_ip column in the database and if it matches then check to see whether it has been there for less than 300 seconds. I have just spent the last couple of hours trying to get this working..it doesn't want to know. It keeps finding the matching IP and disregarding the time calculation.. Thanks for any help. Paul I think you'll find NOW() to be the wrong function to use, as per manual: Returns the current date and time as a value in '-MM-DD HH:MM:SS' or MMDDHHMMSS format, depending on whether the function is used in a string or numeric context: mysql select NOW(); - '1997-12-15 23:50:26' mysql select NOW() + 0; - 19971215235026 As you can see what it returns is clearly unsuitable for what you have in mind. Your best bet is probably to use UNIX_TIMESTAMP(). regards -- Jason Wong Gremlins Associates www.gremlins.com.hk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] newbie - problems with Select and timestamp(14) calculation
On Thursday 18 October 2001 23:11 pm, p.whiter wrote: Thanks for the reply, but the Timestamp(14) column (log_time) in my DB saves the time as '20011018134612' this is the same format as the NOW()+0 I think? I have tried various methods to get this to work. I've gone through the manual and various books I have here but am having no joy at all. I have spent far too much time on this, it really should be quite straightforward to compare against a Timestamp column!! If anyone else has any ideas.. But have you spent any time *reading* the (fine) manual? As I suggested before, lookup UNIX_TIMESTAMP(), it should do what you want. rgds -- Jason Wong Gremlins Associates www.gremlins.com.hk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] newbie - problems with Select and timestamp(14) calculation
Hi, There seems to be several ways to compare time. This is what I use to log out visitors if they do nothing in 1000 seconds. This would be easier to do with sessions, but when I made the site my ISP did not have PHP 4.x available. logtime column type is DATETIME, and it stores the date as mm-dd-. UNIX_TIMESTAMP is seconds from some date in 1970(?), but you have to be prepared for the overflow problem in 2037. I have no idea about the performance issues of this setup, but it works fine for me. Regards, Jyrki Leppala $sql = SELECT (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(logtime)) AS timediff FROM yourtable WHERE sessionid='$sessionid' ; $result = mysql_query( $sql ) or die ( 'Ei voi lukea' ); $row = mysql_fetch_array($result); if ($row[timediff]1000) $userlevel=0; // or whatever you need to do here $sql = UPDATE table SET logtime=SYSDATE(), userlevel='$userlevel' WHERE sessionid='$sessionid' ; $result = mysql_query( $sql ) or die ( 'Ei voi päivittää' ); On 18 Oct 01, at 16:11, p.whiter wrote: From: p.whiter [EMAIL PROTECTED] To: [EMAIL PROTECTED] Date sent: Thu, 18 Oct 2001 16:11:23 +0100 Subject:Re: [PHP-DB] newbie - problems with Select and timestamp(14) calculation Thanks for the reply, but the Timestamp(14) column (log_time) in my DB saves the time as '20011018134612' this is the same format as the NOW()+0 I think? I have tried various methods to get this to work. I've gone through the manual and various books I have here but am having no joy at all. I have spent far too much time on this, it really should be quite straightforward to compare against a Timestamp column!! If anyone else has any ideas.. Thanks Paul -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]