Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

3 most recent entries

Explorer ,
Sep 02, 2010 Sep 02, 2010

Hi,

I''ve been flipping through my Coldfusion book and can't seem to find out what kind of code I need to use to display the three most recent blogs in my database... the three highest 'blog_id'; numbers.

537
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Sep 02, 2010 Sep 02, 2010

wycks wrote:

I''ve been flipping through my Coldfusion book and can't seem to find out what kind of code

That may be because this is probably not a ColdFusion problem.  I presume your blog is stored in a database?  If so, then you probably want a database SQL solution.  The difficulty here, is that each major database management system has a different solution to this problem.

Examples for some of the biggest:

Postgresql:
SELECT firstname, lastname, email
FROM contacts
LIMIT 3

MS SQL Server:
SELECT

...
Translate
Valorous Hero ,
Sep 02, 2010 Sep 02, 2010

wycks wrote:

I''ve been flipping through my Coldfusion book and can't seem to find out what kind of code

That may be because this is probably not a ColdFusion problem.  I presume your blog is stored in a database?  If so, then you probably want a database SQL solution.  The difficulty here, is that each major database management system has a different solution to this problem.

Examples for some of the biggest:

Postgresql:
SELECT firstname, lastname, email
FROM contacts
LIMIT 3

MS SQL Server:
SELECT TOP 3 firstname, lastname, email
FROM contacts

ORACLE:
SELECT firstname, lastname, email
FROM contacts
WHERE ROWNUM <= 3

mySQL:
SELECT firstname, lastname, email
FROM contacts
LIMIT 3

http://blog.daemon.com.au/archives/000301.html

But if you really wanted to, you could probably get the results you want with the ColdFusion 'maxrows' parameter of the <cfquery...> tag.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 02, 2010 Sep 02, 2010

Regarding:

But if you really wanted to, you could probably get the results you want  with the ColdFusion 'maxrows' parameter of the <cfquery...> tag.

Bad idea.  It works but it's inefficient.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Sep 02, 2010 Sep 02, 2010

Dan Bracuk wrote:

Bad idea.  It works but it's inefficient.

Which is why it is listed last and qualifed with "really wanted to".

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Sep 03, 2010 Sep 03, 2010
LATEST

Whichever database you are using, the query should also include an ORDER BY clause. Otherwise the order of the results is indeterminate. You may get the correct results .. or you may not. If you need to enforce a specific order, always use an ORDER BY clause.

>> the three highest 'blog_id'; numbers.

Personally, I would order the results by some sort of timestamp column instead. Assuming your table has one.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources