The SQL query will do the grouping and present them in the correct sequence.
All programming languages require that you iterate over the set of retrieved
records. What you do with them as you retrieve them is up to you.

Code would look quite similar in 'C' and would have the same structure in any
other procedural language, so there is nothing special about PHP in this
example.

On Mon, 10 Jul 2006 13:42:15 +0200 (CEST), [EMAIL PROTECTED] wrote:


>Hello, and thanks for the reply.

>I dont' know PHP, but I can understand that you are suggesting to "manually"
>iterate the records to find the events, and group them by day. Is this right?


>"C.Peachment" <[EMAIL PROTECTED]> ha scritto:  What is wrong with using:

>select EventID, EventDate, EventTime
> order by EventDate, EventTime
> group by EventDate;

>You have a separate display problem - you want
>to put up to three records on the same line. This is
>a language and application specific problem. In PHP,
>using the PDO module and producing output for a
>web page, it can be solved with something like:

>$SqlText = "select EventID, EventDate, EventTime " .
>                   " order by EventDate, EventTime " .
>                   " group by EventDate";

>$Stmt = $dbh->prepare($SqlText);
>$Stmt->execute();

>$Found = false;
>$PriorDate = 0;
>while ($Row = $Stmt->fetch(PDO::FETCH_OBJ)) {
>  $Found = true;
>  if ($Row->EventDate != $PriorDate) {
>    if ($PriorDate != 0) {
>       echo "
>\n";
>    }
>    echo "$Row->EventID, $Row->EventDate";
>  }
>  echo "$Row->EventTime";
>  $PriorDate = $Row->EventDate;

>if ($Found) {
>  echo "
>\n"; // close off last output statement

>$Stmt->closeCursor();


>On Mon, 10 Jul 2006 11:45:24 +0200 (CEST), [EMAIL PROTECTED] wrote:

>>Hello, everybody

>>I have the following problem: I have a table that contains "Events", with the 
>>related date and time:

>>Fields:

>>EventID
>>EventDate
>>EventTime

>>I would like to "group" these records by day, returning all the "times" of 
>>the events, like:

>>EventID, EventDate, EventTime1, EventTime2, EventTime3

>>(I can assume that no more than 3 events happen on the same day).
>>I did this query:

>>SELECT T1.EventDate, T1.EventTime AS Time1, T2.EventTime AS Time2 
>>FROM Events AS T1 LEFT JOIN Events AS T2 ON T2.EventDate = T1.EventDate AND 
>>T2.EventTime > T1.EventTime;

>>This query "works", but it has the following problems: 

>>1. it returns several times the same "record" (can't understand why)
>>2. it takes about 30 seconds (!!) to run, and it consumes all the physical 
>>memory of the system...

>>Any help on this?
>>Thanks in advance for any reply.

>>Kind regards
>>Marco
>> Chiacchiera con i tuoi amici in tempo reale! 
>> http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 





> Chiacchiera con i tuoi amici in tempo reale! 
> http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 



Reply via email to