Ask a Question related to Coldfusion - Getting Started, Design and Development.
-
jjsand28 #1
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
-
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. ... -
Archive::Tar
Sample Code: $a = new Archive::Tar ; $a->add_files( 'images/kids.gif' ) ; @files = $a->list_files() ; ## $files is 'kids.gif' chdir '/tmp' ;... -
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... -
[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.... -
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... -
mxstu #2
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



Reply With Quote

