Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org

Related items

Exporting data to Word with Cold Fusion

How to update/edit data using Cold Fusion

Introduction to Cold Fusion

Diary of a WebObjects Developer

Building an Internet Database

My First Forum - a bulletin board application- index2

You are here: irt.org | Articles | Database | My First Forum - a bulletin board application [ previous next ]

Published on: Thursday 8th April 1999 By: Andrew Shatwell

Displaying the forums

The first screen lists all the available forums along with a short description.

<CFINCLUDE TEMPLATE="check.cfm">

<!doctype html public "-//IETF//DTD HTML 3.2//EN">
<html>
<head>
<title>My first forum</title>
<meta name="Generator" content="HTMLed32 Version 2.0a">
</head>
<body BGCOLOR="#FFFFFF" BACKGROUND="../images/gridpaperbackground2.gif" link="#000080" vlink="#2f2f4f">
<div align="center">
  <IMG SRC="../images/logo2.gif" BORDER="0" ALT="My first forum" width="378" height="78">
</div>
<p>

The first line uses the <CFINCLUDE> tag. As the name suggests, when the server comes across this tag it processes the code found in the defined file, and then continues with the original file.

Using CFINCLUDE allows developers to build up libraries of reusable code which can be referenced by other applications.

In this example we are including the check.cfm file. This is a simple function that checks if the user has logged on and if so, sets a flag log to be 1.

We could have put the contents of check.cfm in a file called application.cfm. Cold Fusion checks for the existence of application.cfm every time it runs a script, and, if found, automatically executes it. However, this bulletin board application is part of a larger package I wrote and there are some instances where I did not want to check if the user had logged on. Rather than re-write the application for the benefit of IRT.org, we're staying with my original script! :-)

<CFQUERY NAME="ListGroups" DATASOURCE="#MyDatabase#">
SELECT tblGroups.GroupID, tblGroups.GroupName, tblGroups.Description,
Count(tblArticles.ArticleID) AS P, Max(tblArticles.Posted) AS LastP
FROM tblGroups LEFT JOIN tblArticles ON tblGroups.GroupID = tblArticles.GroupID
GROUP BY tblGroups.GroupID, tblGroups.GroupName, tblGroups.Description;
</CFQUERY>

<TABLE CELLSPACING="0" CELLPADDING="3">
<tr bgcolor="#D5E6E1">
  <td>&nbsp;</td>
  <td><font size="1" face="Verdana, Arial" color="#000080">Forum</font></td>
  <td align="center">
    <font size="1" face="Verdana, Arial" color="#000080">Posts</font>
  </td>
  <td align="center">
    <font size="1" face="Verdana, Arial" color="#000080">Last post</font>
  </td>
</tr>

<CFOUTPUT QUERY="ListGroups"><tr>
  <td><CFIF log eq 1>
    <CFIF LastP gt login.LastLogin>
      <img src="../images/on.gif" width="22" height="15" border="0" alt="">
    <CFELSE>
      <img src="../images/off.gif" width="22" height="15" border="0" alt="">
    </CFIF><CFELSE>&nbsp;</CFIF>
  </td>
  <td><a href="openforum.cfm?forum=#GroupID#">#GroupName#</a>
    <br><font size="-1">#Description#</font>
  </td>
  <td align="center">
    <font size="1">#P#</font></td>
  <td align="center">
    <font size="1">#dateformat(LastP,"dd-mm-yy")#</font>
  </td>
</tr></CFOUTPUT>
</TABLE>

<p>
<hr width="45%" align="left">
<font size="-1">
<img src="../images/on.gif" width="22" height="15" border="0" alt="on">
&nbsp;&nbsp; New Posts Since Your Last Visit
<br>
<img src="../images/off.gif" width="22" height="15" border="0" alt="off">
&nbsp;&nbsp; No New Posts Since Your Last Visit
</font>

</body>
</html>

The query defined between the <CFQUERY> tags SELECTs the GroupID, GroupName, group Description fields from the database. In addition it counts the number of articles in each forum and obtains the date the last article was posted in each forum. Readers familiar with SQL will notice that the text between the two CFQUERY tags is normal SQL.

The next seven lines are regular HTML. A table is constructed with four columns - the first being empty.

We now will display the results of the query. Code between the opening and closing CFOUTPUT tags is repeated for each record returned by the query. Each record is shown on its own row in the table, so <tr> is shown after then opening <CFOUTPUT> tag and </tr> appears just before the closing <CFOUTPUT>.

There now follows several nested CFIF statements to determine the contents of the first cell in each row. Translated into pseudocode, we have:

Has the user logged on?
  If yes, then: Is the date of the last article posted later than the last time the user logged on?
         If yes, then: Show a picture of a lit lightbulb
         If no, then: Show a picture of a dark lightbulb
   If no, then: Output a space character

Back to Getting Started, or forward to Including files

Related items

Exporting data to Word with Cold Fusion

How to update/edit data using Cold Fusion

Introduction to Cold Fusion

Diary of a WebObjects Developer

Building an Internet Database

©2018 Martin Webb