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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using Route 53, Record Sets & Health Checks 2 Node Exchange 2016 environment 2 99
Problem to go to page 12 93
Webserver access problem 5 73
WEB Farm 6 69
In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

773 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