Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
Medium Priority
?
168 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Accepted Solution

by:
jyokum earned 500 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

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

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

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

618 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