almightyegg Posted November 7, 2006 Share Posted November 7, 2006 is it possible to do something like:mysql count row blah where last_login has been within the past 10 minutes...how would i do time thing ??? sorry if ive confused you all :-X Link to comment https://forums.phpfreaks.com/topic/26514-datetime-stuff/ Share on other sites More sharing options...
ToonMariner Posted November 8, 2006 Share Posted November 8, 2006 mysql count row blah where last_login > NOW() - INTERVAL 1O MINUTESOr something like! Link to comment https://forums.phpfreaks.com/topic/26514-datetime-stuff/#findComment-121293 Share on other sites More sharing options...
almightyegg Posted November 8, 2006 Author Share Posted November 8, 2006 hmm...[code=php:0]$sql2 = mysql_query("SELECT * FROM users WHERE last_login > $time INTERVAL 10 MINUTES");$mem2 = mysql_fetch_array($sql2);$numr = mysql_num_rows($sql2);[/code]are you sure thats a real code :PWarning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/lordofth/public_html/index.php on line 16Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/lordofth/public_html/index.php on line 17 Link to comment https://forums.phpfreaks.com/topic/26514-datetime-stuff/#findComment-121305 Share on other sites More sharing options...
leeming Posted November 8, 2006 Share Posted November 8, 2006 [quote author=almightyegg link=topic=114205.msg464618#msg464618 date=1162944744]hmm...[code=php:0]$sql2 = mysql_query("SELECT * FROM users WHERE last_login > $time INTERVAL 10 MINUTES");$mem2 = mysql_fetch_array($sql2);$numr = mysql_num_rows($sql2);[/code]are you sure thats a real code :PWarning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/lordofth/public_html/index.php on line 16Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/lordofth/public_html/index.php on line 17[/quote]you put...[code]$mem2 = mysql_fetch_array($sql2);$numr = mysql_num_rows($sql2);[/code]its[code]$mem2 = mysql_fetch_array($sql2);$numr = mysql_num_rows($mem2);[/code]your using the query.. not the sql Link to comment https://forums.phpfreaks.com/topic/26514-datetime-stuff/#findComment-121309 Share on other sites More sharing options...
almightyegg Posted November 8, 2006 Author Share Posted November 8, 2006 same errors ??? Link to comment https://forums.phpfreaks.com/topic/26514-datetime-stuff/#findComment-121310 Share on other sites More sharing options...
ToonMariner Posted November 8, 2006 Share Posted November 8, 2006 You missed out teh '-' sign too! ;) Link to comment https://forums.phpfreaks.com/topic/26514-datetime-stuff/#findComment-121313 Share on other sites More sharing options...
almightyegg Posted November 8, 2006 Author Share Posted November 8, 2006 still same errors.....:([code=php:0]$time = gmdate("Y-m-d H:i:s");$sql2 = mysql_query("SELECT * FROM users WHERE last_login > $time - INTERVAL 10 MINUTES");$mem2 = mysql_fetch_array($sql2);$numr = mysql_num_rows($mem2);[/code] Link to comment https://forums.phpfreaks.com/topic/26514-datetime-stuff/#findComment-121314 Share on other sites More sharing options...
stewart715 Posted November 8, 2006 Share Posted November 8, 2006 what unit of time is in your database? it's minutes right? Link to comment https://forums.phpfreaks.com/topic/26514-datetime-stuff/#findComment-121315 Share on other sites More sharing options...
almightyegg Posted November 8, 2006 Author Share Posted November 8, 2006 no its the whole Y-m-d H:i:s....aka 2006-11-07 00:22:47 or whatever ... Link to comment https://forums.phpfreaks.com/topic/26514-datetime-stuff/#findComment-121319 Share on other sites More sharing options...
ToonMariner Posted November 8, 2006 Share Posted November 8, 2006 so why use $tme when NOW() is more appropriate?try putting ( ) around teh calculaion Link to comment https://forums.phpfreaks.com/topic/26514-datetime-stuff/#findComment-121320 Share on other sites More sharing options...
almightyegg Posted November 8, 2006 Author Share Posted November 8, 2006 [code=php:0]$time = gmdate("Y-m-d H:i:s"); //this is my time[/code]NOW() wont work as it isnt GM time... Link to comment https://forums.phpfreaks.com/topic/26514-datetime-stuff/#findComment-121322 Share on other sites More sharing options...
stewart715 Posted November 8, 2006 Share Posted November 8, 2006 hold on i completely misread lol Link to comment https://forums.phpfreaks.com/topic/26514-datetime-stuff/#findComment-121323 Share on other sites More sharing options...
almightyegg Posted November 8, 2006 Author Share Posted November 8, 2006 no...its to see how many members are online (online meaning having clicked on site within the last 10 minutes)and toonmariner...there is no such thing as INTERVAL.... >:( Link to comment https://forums.phpfreaks.com/topic/26514-datetime-stuff/#findComment-121324 Share on other sites More sharing options...
stewart715 Posted November 8, 2006 Share Posted November 8, 2006 [code]<?php$time = mktime(0, 0, 0, 0, 0, 0, date("m"), date("d"), date("Y"), date("H"), date("i")-10, date("s"));$sql2 = mysql_query("SELECT * FROM users WHERE last_login < $time");$mem2 = mysql_fetch_array($sql2);$numr = mysql_num_rows($mem2);?>[/code]maybe? Link to comment https://forums.phpfreaks.com/topic/26514-datetime-stuff/#findComment-121329 Share on other sites More sharing options...
leeming Posted November 8, 2006 Share Posted November 8, 2006 [code]$sql2 = "SELECT * FROM users WHERE last_login > ".gmdate("Y-m-d H:i:s")." - INTERVAL 10 MINUTES";[/code]how about that?i remember looking up the same thing ages ago myself (i use php's time() now.. easy to manipulte)http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.htmlmore info on date and interval Link to comment https://forums.phpfreaks.com/topic/26514-datetime-stuff/#findComment-121331 Share on other sites More sharing options...
stewart715 Posted November 8, 2006 Share Posted November 8, 2006 [quote author=stewart715 link=topic=114205.msg464642#msg464642 date=1162946835][code]<?php//date("i")-10 means 10 minutes ago$time = mktime(0, 0, 0, 0, 0, 0, date("m"), date("d"), date("Y"), date("H"), date("i")-10, date("s"));$sql2 = mysql_query("SELECT * FROM users WHERE last_login < $time");$mem2 = mysql_fetch_array($sql2);$numr = mysql_num_rows($mem2);?>[/code]maybe?[/quote] Link to comment https://forums.phpfreaks.com/topic/26514-datetime-stuff/#findComment-121346 Share on other sites More sharing options...
almightyegg Posted November 8, 2006 Author Share Posted November 8, 2006 nah, that got multipul errors... i am thinking somethingmlike:[code=php:0]$time = gmdate("Y-m-d H:i:s",strtotime(-0010));$sql2 = mysql_query("SELECT * FROM users WHERE last_login > $time");$mem2 = mysql_fetch_array($sql2);$numr = mysql_num_rows($mem2);[/code]the -0010 was me trying to do -10 minutes :( but it takes off 10 hours instead Link to comment https://forums.phpfreaks.com/topic/26514-datetime-stuff/#findComment-121661 Share on other sites More sharing options...
Orio Posted November 8, 2006 Share Posted November 8, 2006 You can do instead of-$time = gmdate("Y-m-d H:i:s",strtotime(-0010));This-$time = gmdate("Y-m-d H:i:s",time()-60*10);Orio. Link to comment https://forums.phpfreaks.com/topic/26514-datetime-stuff/#findComment-121667 Share on other sites More sharing options...
almightyegg Posted November 8, 2006 Author Share Posted November 8, 2006 i echoed $time out and got: 1969-12-31 23:59:59 apart from that it is 6.30pm gm time it is also not 1969 :P that made me giggle :)is there a function like 'i'-10 ???? Link to comment https://forums.phpfreaks.com/topic/26514-datetime-stuff/#findComment-121669 Share on other sites More sharing options...
Orio Posted November 8, 2006 Share Posted November 8, 2006 Running this-[code]<?phpecho gmdate("Y-m-d H:i:s",time()-60*10);?>[/code]Outputed on my server - 2006-11-08 18:23:18Orio. Link to comment https://forums.phpfreaks.com/topic/26514-datetime-stuff/#findComment-121673 Share on other sites More sharing options...
almightyegg Posted November 8, 2006 Author Share Posted November 8, 2006 i missed something out :-\ oops :P that sorts that problem....but i get some errors counting rows...[quote]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/lordofth/public_html/index.php on line 17Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/lordofth/public_html/index.php on line 18[/quote][code=php:0]$time = gmdate("Y-m-d H:i:s",time()-60*10);$sql2 = mysql_query("SELECT * FROM users WHERE last_login > $time");$mem2 = mysql_fetch_array($sql2); //line17$numr = mysql_num_rows($mem2); //line18[/code] Link to comment https://forums.phpfreaks.com/topic/26514-datetime-stuff/#findComment-121676 Share on other sites More sharing options...
Orio Posted November 8, 2006 Share Posted November 8, 2006 I suppose you connected to the DB, right?First, try chaning the line in the following way:$sql2 = mysql_query("SELECT * FROM users WHERE last_login > '$time'");If that doesnt work, let's see if there's any error:$sql2 = mysql_query("SELECT * FROM users WHERE last_login > '$time'") or die(mysql_error());Orio. Link to comment https://forums.phpfreaks.com/topic/26514-datetime-stuff/#findComment-121678 Share on other sites More sharing options...
almightyegg Posted November 8, 2006 Author Share Posted November 8, 2006 half worked...i only get one error now:Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/lordofth/public_html/index.php on line 18??? Link to comment https://forums.phpfreaks.com/topic/26514-datetime-stuff/#findComment-121681 Share on other sites More sharing options...
Orio Posted November 8, 2006 Share Posted November 8, 2006 This-$numr = mysql_num_rows($mem2);Should be-$numr = mysql_num_rows($sql2);Orio. Link to comment https://forums.phpfreaks.com/topic/26514-datetime-stuff/#findComment-121688 Share on other sites More sharing options...
almightyegg Posted November 8, 2006 Author Share Posted November 8, 2006 YAY!!! thanks :) Link to comment https://forums.phpfreaks.com/topic/26514-datetime-stuff/#findComment-121693 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.