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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

829 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