The "best" thing to do is to not mix your display logic with your business logic in the same file: fetching stuff from the DBs hould not be coupled to outputing something based on that fetched data.
Read this lot:
The best thing to do depends on the situation at hand. There are times when Adam's suggestion makes sense. There are others where it is overengineering.
If you are going to have your query, processing, and display code all in one file, it is important that you run your query before you attempt to process the results and that you do any processing before you attempt to display it. However, I don't think it really matters where your coldfusion code is with respect to any html tags.
So before the doctype tag? Thanks
I just doesn't really matter. the doctype, head, body, etc only matter to the browser; the CF tags only matter to CF. The browser doesn't see the CFML, and CF doesn't care about the mark-up one bit: it just ignores it.
The best place - as I said - is not in the same file at all. But if you insist on slapping your business logic in with your display logic, then the only consideration is that you need to set your variables before you use them. Other than that: it simply doesn't matter.
One consideration you might make is - even if it's all thrown into the same one file - at least separate the file itself into sections: have all your CFML code that gets your data at the top, and try to limit the CFML you have mixed in with the mark-up, eg: limit it to stuff like loops and conditionals.
But, seriously, separate your concerns. Dan's pretty much just wrong when he said it's over-engineering. It's just sloppy to not to write tidy, well-maintained, well-organised code.
Where is the best place to put cfqueries, in the <head> </head> or before the html tag? Thanks
In a separate CFM page or CFC then use, respectively, a cfinclude or cfobject tag to access the queries.
Europe, Middle East and Africa