Forum Moderators: coopster

Message Too Old, No Replies

Displaying records in date order...

...even when there is nothing to show.

         

elgumbo

2:20 pm on Jul 1, 2005 (gmt 0)

10+ Year Member



Hi

I am trying to display a list of records in day order but no matter what I try I just can't my head around it. I can list the records in date order, but I need to display them under the relevant days. eg:
--------------------
Monday:
record 1
record 2

Tuesday
record 3

Wednesday

Thurdsday
record 4
---------------------

I am extracting relevant records for this week from the database but I am having real trouble in displaying (grouping?) them in a meaniful way.

My Sql which returns the relevant records is:

SELECT CompanyName, ContactTitle, ContactFirstName, ContactSurname, ContactTel, DAYOFWEEK(ChaseDate) AS DayNumber, ChaseDate
FROM clients
where ChaseDate
>= date_add(CURRENT_DATE, interval 1-DAYOFWEEK(CURRENT_DATE) day)
and ChaseDate
< date_add(CURRENT_DATE, interval 8-DAYOFWEEK(CURRENT_DATE) day)
AND CompanyShow='1'
ORDER BY ChaseDate, CompanyName

Any pointers on what I can do?

Thanks

coopster

3:55 pm on Jul 1, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You could also add a DAYNAME(ChaseDate) AS dayName to your query and then in your loop you simply kick out a new grouping when it changes.
$dayname = false; 
while (looping) {
if ($row['dayName']!== $dayName) {
print $dayName;
$dayName = $row['dayName'];
}
// print record details
}

elgumbo

11:20 am on Jul 5, 2005 (gmt 0)

10+ Year Member



Thanks for that. It got me started on the correct path :)