A Brief Introduction to Cold Fusion

Cold Fusion has nothing to do with experimental physics. It is simply a "gateway" to database files through HTML documents. Cold Fusion is a rich development environment. We are only going to scratch the surface of its capabilities in order to make you aware of this powerful, easy to use tool. Cold Fusion greatly extends the capabilities of web pages without a lot of hassle.

There are two basic Cold Fusion commands: <cfquery> and <cfoutput>

Both are "block" commands, which means that a corresponding "slash" command is REQUIRED for both of them.


The <cfquery> Command

The <cfquery> commands go in the <HEAD> section of your HTML file after the <TITLE>. Here is the format of the <cfquery> command:

<cfquery name = "recordsetname" datasource = "filename">
SQL command goes here (see the SQL Intro)
</cfquery>

"recordsetname" is simply the name of a dataset that you specify. It will be used in the <cfoutput> command below. The only rule is that it cannot have spaces in the name. "filename" is the name of the Access database file on the Cold Fusion server (the "I" drive) that is set up by your local Database Administrator (me in this case). For your Project 8, use "sds5_general" as your datasource.

That's it!!!!! Cold Fusion makes the link to the Access database, then executes the SQL commands to retrieve the requried data, then incorporates the returned data into your HTML document as specified by the <cfoutput> command (see below).


The <cfoutput> Command

The <cfoutput> command tells Cold Fusion what fields of data to present in the HTML file, and in what order. This command can go anywhere within the body of the HTML document. Here is an example of the <cfoutput> command:

<cfoutput query = "recordsetname">
#field1# #field2# #field3# .....
</cfoutput>

The fields of data that you want to have displayed are specified with the "#" (pound sign) surrounding the field names. All fields specified in the <cfoutput> command must have been specified in the SQL statement specified in the <cfquery> command. The "recordsetname" must be the same as in the <cfquery> command above.


A Complete Cold Fusion Example

Here is a complete HTML document that includes Cold Fusion commands to read data from the Proj3data.mdb Access database. This example includes an SQL statement that you can find in the SQL Introduction page.

<HTML>
<HEAD>
<TITLE>Cold Fusion Example</TITLE>

<cfquery name = "salesinfo" datasource = "sds5_general">
SELECT STATE,CATEGORY,UNITS,NETAMT
FROM ORDERS
WHERE (STATE = 'OR' OR STATE = 'NV' OR STATE = 'CA') AND (NETAMT >= 500)
ORDER BY STATE;
</cfquery>

</HEAD>
<BODY>

<H3 ALIGN=CENTER>List of Sales Data for Oregon, Nevada, and Washington</H3>
<H4 ALIGN=CENTER>Sales Amounts Greater Than or Equal To $500</H4>

<cfoutput query = "salesinfo">
#STATE# #CATEGORY# #NETAMT# <p>
</cfoutput>

<H4 ALIGN=CENTER>End of Sales Data List</H4>

</BODY>
</HTML>

Note the paragraph command at the end of the specification of the fields. This causes each line of data to be displayed on separate lines. Remember, all HTML commands apply within the Cold Fusion commands.


Cold Fusion File Naming Convention and Logistics

ALL Cold Fusion HTML documents MUST have the file name ending in ".cfm" This file name prompts your browser (Netscape or Explorer) to initiate a Cold Fusion session. If you use ".html" then all Cold Fusion commands are simply ignored.

Once you have your "cfm" document created, move it to your "I" drive, then "run" it. By "run" it I mean enter the URL in your browser (Netscape or Explorer) and look at the results. You may have to click on the "Refresh" button to get the data to display. Create this document and give it a try. You need to do this before moving to the next phase of the project. Don't forget that the file type is "cfm".


Return to Project 8 Page