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

From: Date: Sun, 02 Aug 2009 22:51:15 +0000
Subject: Re: newbie: how to return one iteration *per unique date (DAY!)* in a timestamp column?
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-46369@lists.php.net to get a copy of this message
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/

« previous php.db (#46369) next »