dhimok Posted September 6, 2007 Share Posted September 6, 2007 Hi! How do I select entries that have been submitted today in sql. thanks Quote Link to comment https://forums.phpfreaks.com/topic/68254-select-todays-entries/ Share on other sites More sharing options...
darkfreaks Posted September 6, 2007 Share Posted September 6, 2007 whats the code? Quote Link to comment https://forums.phpfreaks.com/topic/68254-select-todays-entries/#findComment-343125 Share on other sites More sharing options...
micah1701 Posted September 6, 2007 Share Posted September 6, 2007 'um, what format is the date stamp in mysql? if its standard: YYY-MM-DD then: $today = date("Y-m-d"); $sql = "SELECT * FROM table WHERE datestamp = $today"; Quote Link to comment https://forums.phpfreaks.com/topic/68254-select-todays-entries/#findComment-343126 Share on other sites More sharing options...
dhimok Posted September 6, 2007 Author Share Posted September 6, 2007 date is a timestamp 10 digits Quote Link to comment https://forums.phpfreaks.com/topic/68254-select-todays-entries/#findComment-343131 Share on other sites More sharing options...
darkfreaks Posted September 6, 2007 Share Posted September 6, 2007 actually that would work. it would display the year month and day in number format Quote Link to comment https://forums.phpfreaks.com/topic/68254-select-todays-entries/#findComment-343133 Share on other sites More sharing options...
photowborama Posted September 6, 2007 Share Posted September 6, 2007 'um, what format is the date stamp in mysql? if its standard: YYY-MM-DD then: $today = date("Y-m-d"); $sql = "SELECT * FROM table WHERE datestamp = $today"; Does mysql date stamp every entry? I thought you had to put a date stamp field in the table before you sort off of it... Quote Link to comment https://forums.phpfreaks.com/topic/68254-select-todays-entries/#findComment-343137 Share on other sites More sharing options...
dhimok Posted September 6, 2007 Author Share Posted September 6, 2007 the date field is int(10) unsigned not null Quote Link to comment https://forums.phpfreaks.com/topic/68254-select-todays-entries/#findComment-343140 Share on other sites More sharing options...
micah1701 Posted September 6, 2007 Share Posted September 6, 2007 date is a timestamp 10 digits I'm assuming this 10-digit date field is being populated with each new entry right? then similar to my first suggestion: $today = strtotime(date("Y-m-d")); //returns 10 digit time stamp of midnight this morning $sql = "SELECT * FROM table WHERE date >= $today"; Quote Link to comment https://forums.phpfreaks.com/topic/68254-select-todays-entries/#findComment-343141 Share on other sites More sharing options...
dhimok Posted September 6, 2007 Author Share Posted September 6, 2007 I was wondering How to count entries or hits made each hour of the day? Quote Link to comment https://forums.phpfreaks.com/topic/68254-select-todays-entries/#findComment-343232 Share on other sites More sharing options...
darkfreaks Posted September 6, 2007 Share Posted September 6, 2007 counts each row <?php $row = mysql_fetch_array($res); echo count($row); ?> Quote Link to comment https://forums.phpfreaks.com/topic/68254-select-todays-entries/#findComment-343239 Share on other sites More sharing options...
dhimok Posted September 6, 2007 Author Share Posted September 6, 2007 how do we count in sql Quote Link to comment https://forums.phpfreaks.com/topic/68254-select-todays-entries/#findComment-343247 Share on other sites More sharing options...
darkfreaks Posted September 6, 2007 Share Posted September 6, 2007 Example: <?php $res = mysql_query("select * from blah") // a query that returns an empty set $row = mysql_fetch_array($res); // get's 0 since there's no return echo count($row); // echos 1 - since $row is not an array echo $row[0]; // echos "", but casts $row as an array? echo count($row); // echos 0 now ?> Quote Link to comment https://forums.phpfreaks.com/topic/68254-select-todays-entries/#findComment-343249 Share on other sites More sharing options...
micah1701 Posted September 6, 2007 Share Posted September 6, 2007 I was wondering How to count entries or hits made each hour of the day? why didn't you ask that then? to count the hits for today, use my previous code then just count the rows returned: $today = strtotime(date("Y-m-d")); $sql = mysql_query("SELECT * FROM table WHERE date >= $today"); echo mysql_num_rows($sql); to get results by hour, modify the $today string in from my example. look at http://www.php.net/date and http://www.php.net/strtotime Quote Link to comment https://forums.phpfreaks.com/topic/68254-select-todays-entries/#findComment-343273 Share on other sites More sharing options...
dhimok Posted September 6, 2007 Author Share Posted September 6, 2007 Ok all I want to do is to loop all hrs of the day like 00 01 02 03 04 05 06 ... 12 13 ... 20 21 22 23 and then get the nr of hits for each one Quote Link to comment https://forums.phpfreaks.com/topic/68254-select-todays-entries/#findComment-343352 Share on other sites More sharing options...
micah1701 Posted September 7, 2007 Share Posted September 7, 2007 didn't test this but how 'bout: <?php $start= strtotime(date("Y-m-d")); $sql = mysql_query("SELECT date FROM table WHERE date >= $start"); for($i=0;$i<mysql_num_rows($sql); $i++){ $date = mysql_result($sql,$i,0); $nextHour = $start + (60*60); if($date >= $start && $date < $nextHour){ $hour[$i] = $hour[$i] + 1; } $start= $nextHour; } print_r($hour); //array of hours with values equal to number of entries each hour ?> Quote Link to comment https://forums.phpfreaks.com/topic/68254-select-todays-entries/#findComment-343411 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.