Skip to main content
Inspiring
July 7, 2006
Question

No Repeat Region

  • July 7, 2006
  • 11 replies
  • 1377 views
I invoked a CFC to give me the results of a query inside the CFC. How to I
make it so only the newest record shows and not all the results? Do I have
to set the repeat region manually to only show one or is there something I
can add to the <cfoutput query="news">?

<cfoutput query="news">
<tr>
<td class="maintext_bold">#DateFormat(news.Date,"mm/
dd/ yyyy")#</td>
</tr>
<tr>
<td class="maintext">#news.Story#</td>
</tr>
</cfoutput>

--
Wally Kolcz
Developer / Support


This topic has been closed for replies.

11 replies

BKBK
Community Expert
Community Expert
July 7, 2006
You could put your displaying code within

<cfif news.Date GT someDate>
<!--- display news --->
</cfif>

If showing the newest result is all you need, then it might be more efficient to do that already at the query. For example, by selecting news "where date > #someDate#".



BKBK
Community Expert
Community Expert
July 8, 2006
?? You lost me on that one ??

I made two suggestions. Other posters have in fact repeated them.

1) Get all news, but display just the new news (inefficient if this is all there is to it)

<cfset someDate = createdate(2006,4,22)>
<cfoutput query="news">
<cfif news.Date GT someDate>
<tr>
<td class="maintext_bold">#DateFormat(news.Date,"mm/
dd/ yyyy")#</td>
</tr>
<tr>
<td class="maintext">#news.Story#</td>
</tr>
</cfif>
</cfoutput>

2) (a) code the query to select the latest news since a given date

<cfset someDate = createdate(2006,4,22)>
<cfquery name="news" datasource="#Request.MainDSN#">
SELECT News_ID, Story,Date
FROM ms411.news
WHERE Date > #createodbcdatetime(someDate)#
ORDER BY Date DESC
</cfquery>

(b) code the query to select the latest news item (more or less Dan Bracuk's suggestion)

<cfquery name="news" datasource="#Request.MainDSN#">
SELECT News_ID, Story,Date
FROM ms411.news
WHERE Date = (SELECT MAX(date) FROM ms411.news )
</cfquery>