Jump to content

Select todays entries


dhimok

Recommended Posts

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";

 

 

Link to comment
Share on other sites

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 
?> 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.