Solved

Building an unordered list based on an array of objects NEED AN EXPERT! please help (my first question ever)

Posted on 2003-10-29
2
149 Views
Last Modified: 2013-12-24
Hi!
I have a database of news articles and would like to make unordered list based on post date.
For example:
<ul>
    <li>year1</li>
         <ul>
             <li>january</li>
                    <ul>
                           <li>(1/1/2003) article title </li>
                   </ul>
            <li>February</li>
                   <ul>
                           <li>(2/1/2003) article title2</li>
                           <li>(2/2/2003) article title3</li>
                   </ul>
         </ul>
     <li>year2</li>
          <ul>
             <li>january</li>
                    <ul>
                           <li>(1/1/2003) article title </li>
                   </ul>
          </ul>
</ul>
i have a query such as
<cfquery name="getnews" datasource="news">
 select postdate, headline, introduction from tblNews
</cfquery>
I put all of the data into an array for easy access like:
<cfset myList= ArrayNew(1)>
<cfset counter=1>
<cfloop query="getnews">
<cfset myList[counter]=StructNew()>
<cfset myList[counter].year="#year(postdate)#">
<cfset myList[counter].month="#month(postdate)#">
<cfset myList[counter].date="#DateFormat(postdate,'mm/dd/yyyy')#">
<cfset myList[counter].headline="#headline#">
<cfset myList[counter].intro="#introduction#">
<cfset counter=counter+1>
</cfloop>
so I can access stuff with a loop
<cfloop index="i" from="1" to="#ArrayLen(myList)#">
<cfoutput>
#myList[i].year#<br>
#myList[i].month#<br>
#myList[i].date#<br>
#myList[i].headline#<br>
</cfoutput>
</cfloop>
i want to be able to construct an unordered list with the structure i described above from either the array or directly from query whichever is easier.
0
Comment
Question by:SrdanReljic
2 Comments
 
LVL 12

Accepted Solution

by:
jyokum earned 125 total points
ID: 9647571
don't know what kind of database you're using so the functions in the query might be slightly different. This example uses a MS Access database



<cfquery name="getnews" datasource="EE">
 select postdate, year(postdate) as theYear, month(postdate) as theMonth, headline, introduction from tblNews
 order by year(postdate), month(postdate), postdate
</cfquery>

<ul>
<cfoutput query="getnews" group="theYear">
      <li>#getnews.theYear#</li>
            <ul>
            <cfoutput group="theMonth">
                  <li>#dateformat(getnews.postdate,'mmmm')#</li>
                        <ul>
                        <cfoutput>
                              <li>(#dateformat(getnews.postdate,'mm/dd/yyyy')#) #getnews.headline#</li>
                        </cfoutput>
                        </ul>
            </cfoutput>
            </ul>
</cfoutput>
</ul>
0
 

Author Comment

by:SrdanReljic
ID: 9647843
Exactly what I've needed. Thank you so much! I use sql server 2000.
points are yours....
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now