Re: newbie: how to return one iteration *per unique date (DAY!)* in a timestamp column?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Govinda wrote:
Hi all

I'm translating some code from another server-side language into PHP, and I need something that 'summarizes' results found from a MySQL SELECT. I.e. -

$foundTrackingRows=mysql_query("SELECT...
while ($TrackingRow = mysql_fetch_object($foundTrackingRows)) {...

..such that the while loop only loops *ONCE per unique _date_ found (regardless of the hour/min./sec.)* in my column which is of type
TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP PRIMARY KEY

For example, if I have column values like these:
2009-08-01 07:01:00
2009-07-30 18:16:37
2009-07-30 17:49:06
2009-07-27 17:35:52
2009-07-27 17:24:21
2009-07-27 17:23:03
..then my while { loop would only fire 3 times.

I do my RTFM; can someone just give me a good point in the right direction.
Thanks!

You need to do this on the mysql side, not in php - php can't summarize the data before processing it, so you need to use something like the date() function in mysql on your timestamp column.

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date

without knowing your original query it's hard to give an example, but:

select distinct date(timestamp_column) from table;

--
Postgresql & php tutorials
http://www.designmagick.com/


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux