Copy link to clipboard
Copied
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.
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Dan Bracuk wrote:
Bad idea. It works but it's inefficient.
Which is why it is listed last and qualifed with "really wanted to".
Copy link to clipboard
Copied
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.