To get all the articles for a specific timeframe, you will need to work with
the 'where' statement for your date field.

Select article_id, article_title, date_entered from articles where
date_entered >= "01/01/2007" and date_entered <= "12/31/2007"

Different databases have different methods of dealing with date fields (and
how to filter against them), but above is a simple and basic format.

What you will want to do is use the date formatting that is the same as the
way the date is in your date_entered field.  (eg.  if your dates are stored
as 12/15/2007, then the 'mm/dd/yyyy' pattern works, if your date is
"2007-12-15" then you would use the 'yyyy-mm-dd' pattern.  However it is
saved in the database, you will want to match the pattern.)

Hope this helps,
William

-- 
William E. Seiter
 
Have you ever read a book that changed your life?
Go to: www.winninginthemargins.com
Enter passkey: goldengrove
 
Web Developer 
http://William.Seiter.com
-----Original Message-----
From: John Barrett [mailto:[EMAIL PROTECTED] 
Sent: Sunday, December 16, 2007 11:05 PM
To: CF-Newbie
Subject: cfquery loop

I have a page that gets article data from a database(I think that it is
called a master/detail page). I can with help from this list display all the
articles, but I would like to display the articles by year. That is, loop
through the article_id for each year(such as 1 to 12 for the fist year. I
was think that I could use this, but it still displays all the articles.
Could somebody please help. When I take out the "SELECT * FROM articles" I
get a "Can not issue empty query." error.
Thanks so much,
John:
<cfquery name="get_articles" datasource="articles">

        Select article_id, article_title, date_entered from articles
   </cfquery>
   
   <cfquery name = "get_articles" 
                                                          dataSource =
"articles"> 
                                                          SELECT * FROM
articles
                                                        </cfquery>
                                                        <cfloop query =
"get_articles"> 
                                                        <cfset Start = 1> 
                                                        <cfset End = 12> 
                                                        
                                                        </cfloop>

Here is the original code:
<!--- main Page, to display links--->
<cfquery name="get_articles" datasource="articles">
    Select article_id, article_title, date_entered from articles
</cfquery>


<cfoutput query="get_articles">
  <a href="complete_article_page.cfm?article_id=#article_id#"
target="_blank">#article_title#</a><br>
  #date_entered#<p>
</cfoutput>

<!--- output page, to display articles--->
 <cfquery name="get_articles" datasource="articles">
    Select article_id, article_title, date_entered from articles
   </cfquery>
   
<cfquery name="get_article" datasource="articles">
    select article_title, article_text, date_entered from articles where
article_id = '#article_id#' 
 </cfquery>

<cfoutput>#get_article.article_title#</cfoutput></p>
<cfoutput>#get_article.article_text#</cfoutput></p>




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;160198600;22374440;w

Archive: 
http://www.houseoffusion.com/groups/CF-Newbie/message.cfm/messageid:3187
Subscription: http://www.houseoffusion.com/groups/CF-Newbie/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.15

Reply via email to