Ask a Question related to Coldfusion - Getting Started, Design and Development.

  1. #1

    Default creating an archive

    I am trying to create an archive menu that would look like this

    November 2004 (10)

    where the (10) is the number of posts for that month and year.

    This is what i have so far but everything else I tried hasn't worked. i tried
    loops and month, year functions and I'm running out of hair to pull out. Aso
    this menu is a going to be a set of links so how would I quer the db to get
    only those records? when i do a set

    <cfset thismonth = datepart('m',#passedVariable1#)>

    All I get is an error.

    I don't necessarily need it done for me as i wouldn't learn that way but a
    good tutorial or some suggestions would be very helpful.

    <!--- get the news items --->
    <cfquery name="getnewsArc" datasource="#Application.dsn#">
    select * from sy_news
    order by newsDate desc
    </cfquery>

    <ul>
    <cfoutput query="getNewsArc" group="newsDate">
    <li>#DateFormat(getNewsArc.newsDate, 'mmmm yyyy')#</li>
    </cfoutput>
    </ul>

    jjsand28 Guest

  2. Similar Questions and Discussions

    1. Archive::Zip problem
      Maybe I've misunderstood something. But when calling $zip->contents() I keep getting characters added and/or replaced within the returned string. ...
    2. Archive::Tar
      Sample Code: $a = new Archive::Tar ; $a->add_files( 'images/kids.gif' ) ; @files = $a->list_files() ; ## $files is 'kids.gif' chdir '/tmp' ;...
    3. using Archive::Zip
      Hello, I have over 200 zip files in about 100 sub-directories of say c:\docs. Each zip file contains one MS Word doc file. The name of the doc...
    4. [PHP-DEV] PHP archive
      Not so long ago, it was proposed that we should have an PHP archive model like Java does. I think it might me useful for application deployment....
    5. Archive
      On Fri, 25 Jul 2003 12:31:03 GMT, "nospam" <bruceradtke@REMOVEspamREMOVE.earthlink.net> wrote: I think you misread that - comp.unix.sco is no...
  3. #2

    Default Re: creating an archive

    I'll let you work out the syntax details for your database type, but here are
    some thoughts that might help you get started.

    To get the total post counts by month/year, try using database date functions,
    instead of CF date functions. The functions for your database may vary, but
    something like:

    -- not tested
    SELECT datePart(m, newsDate) As MonthNumber,
    dateName(mm, newsDate) As MonthName,
    datePart(yyyy, newsDate) AS YearNumber,
    count(*) AS TotalPosts
    FROM sy_news
    GROUP BY datePart(m, newsDate), datePart(yyyy, newsDate)
    ORDER BY YearNumber, MonthNumber


    If your database does not have a dateName() function, you could just extract
    the month number and use CF's MonthAsString(monthNumber) function.

    There are a few different methods for extracting data for an entire month.
    The easiest method is probably to just pass the month and year numbers as url
    parameters and and use your database's datePart() function in your cfquery:


    -- not tested
    SELECT newsDate, otherColumns...
    FROM sy_news
    WHERE datePart(m, newsDate) = #url.monthNumber# AND
    datePart(yyyy, newsDate) = #url.yearNumber# AND



    However, using functions can sometimes cause database engines to ignore
    indexes and reduce query performance. An alternative might be to use the url
    parameters to create start and end date variables and use those in your cfquery:


    <cfset firstOfThisMonth = createDate(url.yearNumber, url.monthNumber, 1)>
    <cfset firstOfNextMonth = dateAdd("m", 1, firstOfThisMonth)>
    <cfquery ....>
    SELECT newsDate, otherColumns...
    FROM sy_news
    WHERE newsDate >= #createODBCDate(firstOfThisMonth)# AND
    newsDate < #createODBCDate(firstOfNextMonth)# AND
    </cfquery>




    mxstu Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139