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
155 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

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Question to locate the problem 18 133
Stream live video from Raspberry Pi camera 22 264
Why is my Splunk Web URL not working? 2 85
app server have enough resources... 2 62
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…
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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