Link to home
Start Free TrialLog in
Avatar of rrattie
rrattieFlag for United States of America

asked on

Generate dynamic lists with subcategory headers

I am trying to create lists that have subcategory headers using CF with a MSSQL db.

So it would look like

SUBCATEGORY
   list item1
   list item2
   list item3
   list item4

SUBCATEGORY2
   list item1
   list item2
   list item3
   list item4

   
My DB Table and columns are:

Table: Links
Columns: URL, linkID, linkOrder, pageID, pubStatus, linkType, linkLabel, linkSubCatID, linkLabelAcronym

I have another table, LinkSubCategories that corresponds to the linkSubCatIDs. I want to use the names of the Subcategories as the headers to each list.  Does this make sense?
<CFQUERY NAME="qGetListLinks" DATASOURCE="RAA_external">
    SELECT      *
    FROM        Links
    WHERE 		PubStatus IS NOT NULL 
    AND         pageID = '#URL.ID#'
    Order by linkOrder ASC
    </CFQUERY>
<cfinclude template="../breadcrumbs.cfm">
<br />
<br />
<ul>
  <cfoutput query="qGetListLinks">
 
  
  <cfif qGetListLinks.linkType LT "1" >
      <li>There is no content for this page. If you feel this is a mistake, feel free to contact the <a href="contact_form.cfm">webmaster</a>.</li>
	  <cfelseif qGetListLinks.linkSubCatID EQ "5"  >
      <li><a href="#qGetListLinks.URL#" target="_blank">#qGetListLinks.linkLabelAcronym# - #qGetListLinks.linkLabel#</a></li>
    <cfelseif qGetListLinks.linkType EQ "4" >
      <li><a href="#qGetListLinks.URL#" target="_blank">#qGetListLinks.linkLabel#</a></li>
	  <cfelseif qGetListLinks.linkType EQ "3" >
      <li><a href="#qGetListLinks.URL#" target="_blank">#qGetListLinks.linkLabel#</a></li>
	  
      <cfelse>
      <li><a href="index.cfm?ID=#qGetListLinks.pageID#&Type=#qGetListLinks.linkType#" >#qGetListLinks.linkLabel#</a> </li>
    </cfif>
  </cfoutput>
</ul>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of duncancumming
duncancumming
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I missed out a part of the query.

INNER JOIN LinkSubCategories  
       ON Links.linkSubCatID =  LinkSubCategories.SubCatID
Avatar of rrattie

ASKER

AWESOME!! I'm 90% there now!

As I said in my original question/statement. I want it to be an unordered list.

I used the code you posted, but I put in a UL, LI..etc...

The only problem I have is that is shows as:

SUBCATEGORY
   list item1
   list item2
   list item3
   list item4

     SUBCATEGORY2
       list item1
       list item2
       list item3
       list item4


Instead of:

SUBCATEGORY
   list item1
   list item2
   list item3
   list item4

SUBCATEGORY2
   list item1
   list item2
   list item3
   list item4

Any ideas?

Sounds like a problem with an unclosed </li> or </ul>.  Here's a modification of my example to use ul/li


<cfoutput query="qGetListLinks" group="SubCategory">
	#qGetListLinks.SubCategory#
	<ul>
	<cfoutput>
		<li>#qGetListLinks.linkLabel#</li>
	</cfoutput>
	</ul>
</cfoutput>

Open in new window

Avatar of rrattie

ASKER

LOLOLOL!! Man.. I can't believe I missed that.  Oh well.  100% functioning as I wanted.

As usual, you are super fast and efficient. Less than an hour between me submitting the question and you solving it!
Avatar of rrattie

ASKER

Fast and Accurate Solutions Always!