Jump Start To ColdFusion MX - Showing The Results Of A Query
(Page 3 of 6 )
Ok, now that we know how to query a database, let's see how we can show the results of that query. Remember the <cfoutput> tag we talked about earlier in this article? This tag will loop through a recordset when the query attribute is used. Here's how to set up the output of our query from earlier:
<cfoutput query="myQuery">
#col1# #col2#<br>
</cfoutput> That's all you have to do to output a result set from a query -- It's that simple! Any HTML tag can be placed inside a <cfoutput> tag as well. For example:
<cfoutput query="myQuery">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td>#col1#</td>
<td>#col2#</td>
<tr>
</table>
</cfoutput> The <cfoutput> tag is a very powerful tag that has many cool features that are beyond the scope of this article. I will compose a more advanced article with these features explained in depth another day.
On the Winodws platform variables are not case sensitive. So myquery and myQuery refer to the same variable. You can have the same variable in different scopes though. I would not recommend doing this, but it is possible. For instance, you can have form.myvar and url.myvar, but this is not good coding practice -- I just wanted to state that it was indeed possible.
Sending Email Sending email is a very common task that many developers have to do in many of the applications we build. In ColdFusion, sending email is very simple. Just like the other tags that we have used previously in this article, this tag is called what it does; <cfmail>. The <cfmail> tag is what allows developers to send email through their applications. Here is how to use this tag:
<cfmail from="me@me.com" to="you@you.com" subject="This is an email from ColdFusion">
Hello From ColdFusion MX!
</cfmail> This will send an email to the 'to' address with the body of 'Hello From ColdFusion MX'. There are other attributes that this tag can use are bcc, cc, type (text or HTML), query, timeout, startrow, endrow, and many others. This is a powerful tag but it was not design to be a mail-sending engine -- there are third-party mail tags that are much better than the default <cfmail> tag but at least you do not have to buy a third-party tool to send mail out of the box.
Next: Looping In ColdFusion >>
More ColdFusion Articles
More By Clint Tredway