Question : ColdFusion sort problem: in a sorted list of records, white and gray background colors do not consistently alternate

My question in brief: if I have several documents that have the same DocumentPublicationDate, or the same DocumentTitle, then how can I get ColdFusion to sort them with alternating background colors?

Details:

1. Here's my current problem, which I have been reviewing for much of today. gdemaria, _agx_, Brichsoft, and other experts have helped me with this application to display CEP documents. Currently I am trying to group records in a readable, user-friendly list using alternating white and gray backgrounds. But my pages do not consistenly display orderly, alternating background colors.

2. I will give an example. Take a look at this page:

http://ebwebwork.com/cep/press/

You will see that, instead of the expected alternating background colors, that (at the beginning) there are two white backgrounds slumped together. Then the alternating background colors proceed as expected.

3. I believe I know why the problem occurs. The default sort order for these pages is:

D.DocumentPublicationDate DESC, D.DocumentTitle, D.DocumentID, F.FileName

You will note that, on this page, three records all have the same DocumentPublicationDate: June 30, 2010. So, when ColdFusion tries to sort by DocumentPublicationDate, it must "sort" three records with the same DocumentPublicationDate. This causes the conflation of background colors -- I am fairly confident of this.

4. In a similar way, when I sort documents (or records) by Title, then documents that start with "School" get lumped together, causing further conflation of background colors.

5. Hmmm. How can I fix this? I need to tell ColdFusion to distinguish among database records that often have the same characteristics: same publication date; or same first word in their titles.

6. I organize records using the CFOUTPUT GROUP attribute and the CurrentRow MOD 2 IS 1 function:

  <cfif CurrentRow MOD 2 IS 1>
        <cfset bgcolor="##ffffff">
        <cfelse>
        <cfset bgcolor="##f7f5f5">
  </cfif>

... that is straightforward.

7. Here is the query that I use to query the database for documents that have files marked "isPressRelease" ... if a document has a file that is a press release, then the press release file shows up on the Press Releases page:

<!--- query getDocumentsandFiles: select columns from tables tbl_CEP_Documents D, tbl_CEP_Document_Topic T, tbl_Document_Has_Topic H, tbl_CEP_files F --->
<!--- to display CEP Document Title, Author, Abstract, Publication Date; and CEP Files associated with those documents; and download links to those files --->

<cfquery name="getDocumentsandFiles" datasource="#ds#">
SELECT D.DocumentID
         , D.DocumentTitle
     , D.DocumentType
     , D.DocumentAuthor
     , D.DocumentAbstract
     , D.DocumentPublicationDate
     , T.DocumentTopicID
     , T.DocumentTopic
     , H.DocumentID
     , H.DocumentTopicID
     , F.DocumentID
     , F.FileID
     , F.FileName
     , F.FileLinkText
     , F.FileExtension
     , F.FileType
     , F.FileSize
     , F.IsPressRelease
FROM tbl_CEP_Documents D, tbl_CEP_Document_Topic T, tbl_Document_Has_Topic H, tbl_CEP_files F
WHERE D.DocumentID = H.DocumentID
AND D.DocumentID = F.DocumentID
AND F.IsPressRelease = 1
ORDER BY D.DocumentPublicationDate DESC, D.DocumentTitle, D.DocumentID, F.FileName
</cfquery>

My question: if I have several documents that have the same DocumentPublicationDate, or the same DocumentTitle, then how can I get ColdFusion to sort them with alternating background colors?

I hope this question is lucid. Thank you for your help.

Eric

Answer : ColdFusion sort problem: in a sorted list of records, white and gray background colors do not consistently alternate

That means you needs some work on your query it's got a lose join somewhere

FROM tbl_CEP_Documents D
   , tbl_CEP_Document_Topic T
   , tbl_Document_Has_Topic H
   , tbl_CEP_files F
WHERE D.DocumentID = H.DocumentID
AND   D.DocumentID = F.DocumentID
AND   F.IsPressRelease = 1
ORDER BY D.DocumentPublicationDate DESC, D.DocumentTitle, D.DocumentID, F.FileName


Looking at this, I see the _Topic table included in the from clause, but there are no join conditions for this table (nothing in the where clause).

Btw, why aren't you using the standard format for joining?


FROM tbl_CEP_Documents D
 inner join  tbl_CEP_Document_Topic T on t. ??????
 inner join  tbl_Document_Has_Topic H on D.DocumentID = H.DocumentID
 left join tbl_CEP_files F on D.DocumentID = F.DocumentID and F.IsPressRelease = 1
ORDER BY D.DocumentPublicationDate DESC
              , D.DocumentTitle
              , D.DocumentID
              , F.FileName

Random Solutions  
 
programming4us programming4us