CFLoop Display query results

Thread Solved

Join Date: Jan 2008
Posts: 10
Reputation: Prodian is an unknown quantity at this point 
Solved Threads: 0
Prodian Prodian is offline Offline
Newbie Poster

CFLoop Display query results

 
0
  #1
Aug 1st, 2008
Background Info: I have 2 tables one called cats with categories (ie:Administration) and catid (ie:1,2,3,4..etc.) and another table called links which has catid(ie: 1,2,3,4...etc.), url, title.

Here is what Im trying to do: I already have it displaying everything nice and pretty but now i need to change up how its displayed. I just need the link title under the category. Sounds easy right? Here is what I need it to look like:

Administration
Link
Link
Link
Category2
Link
Link
Link

Problem: Nothing can be hard coded, I can not have a query say where category = administration. The reason nothing can be hard coded is because users can Add/Edit/Remove links and categories without me having to go in and edit code every time someone wants to make changes. I was thinking about using cfloop, find the max catid and counting up to the max catid while looping through the query with the loopnumber.

Some code: Here is some code that lists all the links in a table.
  1.  
  2. <cfquery name="links" datasource="#application.sb_ds#" username="#application.sb_username#" password="#application.sb_password#">
  3. SELECT links.name, links.webUrl, cats.category, links.linkid, links.catid, cats.catid
  4. FROM zeke_links links, zeke_cats cats
  5. WHERE links.catid = cats.catid
  6. ORDER BY cats.category, name;
  7. </cfquery>
  8.  
  9. <div style="center">
  10. <cfif Form.category EQ "Select a category">
  11.  
  12. <cflocation url="body.cfm">
  13.  
  14. <cfelseif Form.category EQ "Full List">
  15.  
  16. <center><h2>Full List</center></h2>
  17.  
  18. <TABLE BORDER="2" CELLPADDING="5" CELLSPACING="5">
  19. <tr>
  20. <th align="Center">Name</th>
  21. <th align="center">URL</th>
  22. <th align="center">Category</th>
  23. </tr>
  24. <cfoutput query="links">
  25. <tr><td>#links.name#</td>
  26. <cfif links.webUrl eq "">
  27. <td>No Website Url Submitted!</td>
  28. <cfelse>
  29. <td><a href="#links.webUrl#" target="blank">#links.webUrl#</a></td>
  30. </cfif>
  31. <td>#category#</td>
  32. </tr>
  33. </cfoutput>
  34. </table>

I am fresh out of ideas, any help would be awesome. Thanks.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 60
Reputation: hinde is an unknown quantity at this point 
Solved Threads: 4
hinde hinde is offline Offline
Junior Poster in Training

Re: CFLoop Display query results

 
0
  #2
Aug 2nd, 2008
I am not giving you all of the code to do exactly what you need, but if you read this code below closely you should be able to get out of your rut with this assignment.
  1. <cfset strLastCatName = "">
  2. <cfoutput query="LINKS">
  3. <cfif LINKS.Category NEQ strLastCatName>
  4. <cfset strLastCatName = LINKS.Category>
  5. #LINKS.Category# <br />
  6. </cfif>
  7. <a href="#links.webUrl#" target="blank">#links.webUrl#</a><br />
  8. </cfoutput>
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 10
Reputation: Prodian is an unknown quantity at this point 
Solved Threads: 0
Prodian Prodian is offline Offline
Newbie Poster

Re: CFLoop Display query results

 
0
  #3
Aug 4th, 2008
That helps a lot, thanks for pointing me in the right direction hinde.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the ColdFusion Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC