Build Master/Detail page in ColdFusion
ColdFusion Master/Detail Pages
Page 1, Page 2, Page 3
After experimenting with some ColdFusion, I found that it is an excellent Web language and probably the most efficient. I say efficient because the definition is:
efficient - Acting or producing effectively with a minimum of waste, expense, or unnecessary effort. Exhibiting a high ratio of output to input.
And that's exactly what makes this language awesome. if ColdFusion does not fit that definition, honestly I dont know what does. I just wanted to share what I had time to share to the Ultradev community regarding ColdFusion. There are plenty of CF resources available online if you plan to really get into ColdFusion.
This tutorial will demonstrate a pair of dynamic
Master/Detail Pages and how simple and easy something like this is using ColdFusion.
Inevitably, it will also demonstrate how to dynamically display records from
a database. You might be looking to see if this tutorial is long, but believe
me, it could have been done in about 3 paragraphs, but I overly exaggerated
the content to make it as simple as possible. If you don't believe me, look
at the final code of both of these pages and see
for yourself all that you will be typing. Tutorial assumes no experience with
ColdFusion at all. Lets get started.
Prior to jumping in, I want to introduce you to a few tags that will be used so that you arent just copying and typing without understanding.
used to output ColdFusion variables, more on this below...
2. <cfquery> This tag does a whole lot, but in our tutorial, it ultimately opens a Recordset for us. This tag and the SQL is all you need to open a Recordset.
3. #URL.CatID# holds a variable called CatID passed in a queryString. This is synomous to ASP's Request.QueryString("CatID"). We will be using this to pass variables through a QueryString and retrieve it on the next page.
4. Variables have to be surrounded by #. So if we have a variable called CatID, ColdFusion can only read it if it is written as such #CatID#. In addition, variables have to be within outputted with the <cfoutput> tag as mentioned earlier. So in order for ColdFusion to output this variable, it must be typed as such
isn't that cool!
Upon this, we are off to conquer the World ... well not really but it's ok to dream and anyway ColdFusion will make you feel that way o)
Lesson: Master Page - part 1
Database: You should have a database with 2 tables. The second Table should have a foreign key of the First table's Primary Key. huh? I think i said that backwards. A simple example would be:
|download a database to use|
|ManufacturerID Primary key||ProductID Primary key|
|ManufacturerID foreign key|
DSN: Please have a DSN name set up for your database. You can do this locally or on a remote server.
1. Open a new page in UD or in any textEditor. I will be using Notepad just to show you how easy & fun coding ColdFusion is. Well, also because I run win98 on 64 mb RAM and UD will take a long time to open ... just kidding.
Save your new page as Master.cfm. The page should have the basic html tags:
If you use Ultradev or Dreamweaver, the html will be all ready for you.
Leave some room above the <html> tag to type your ColdFusion
Above the HTML start by typing
4. This is the basic tag to open your recordset. We need to simply add our SQL which those of who use Ultradev should know the basic syntax of as we see it all the time. It's that stuff you always see in the Recordset dialog box o).
need to name our Recordset and call the DSN. Watch how easy. It will be
added in the first tag.
<cfquery name="rsMaster" datasource="udnewbie">
SELECT CatID, CatTitle
Name is where you name your Recordset and datasource is where you type the name of your DSN for the database you are using. I named my Recordset "rsMaster" and my DSN is called "udnewbie"
Lesson: Master Page - part 2
We have just opened our Recordset, we need to display the Records on the page now.
What would the ASP variable for our CatTitle database column?
Well in ColdFusion, it is:
this in between the body tags:
7. Remember what we said earlier about how ColdFusion displays output, we need to use the <cfoutput> tag, so change it to:
last thing we have left to do is tell the output which recordset to take
this variable from. This also goes in the first tag:
9. Look at your page through the web browser. We have just dynamcially displayed the Category Titles from our Database.
Go to Page 2
Starting out as a fine artist, Omar Elbaga gradually moved to computer graphic arts. He was particularly amazed by the power of the World Wide Web, so he embarked upon building small-scale sites for fun utilizing HTML and his Art background. Falling in love with designing web pages and its potential, he began a career in web design. Omar has since been in the web development field for several years. With his head in computer books nearly 24 hours a day, Omar moved on to enhance his skills from web design to web programming.
Most of his work involves building database-driven web sites for small companies. Omar is currently running a popular Dreamweaver MX resource site named dmxfire.com