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

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- index5

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

Opening a thread

This script displays the messages posted in specific threads. It is called from openforum.cfm and the variables defining which message thread to display are passed in the URL.

The URL to reach this page will be along the lines of http://www.myforum.com/cfm/openthread.cfm?forum=1&ThreadID=2

<CFPARAM NAME = "useraccess" DEFAULT="Public">
<CFIF log eq 1><CFSET useraccess = login.access></CFIF>
<CFQUERY NAME="ForumDetails" DATASOURCE="#MyDatabase#">
  SELECT * FROM tblGroups WHERE GroupID = #forum#

At the top of the file we include the ubiquitous check.cfm file. As in openforum.cfm the next stage is to check whether the user has permission to view articles in this forum.

The CFPARAM tag is used to define variables with a default value. If a variable does not exist then it is given the value specified in the tag. If the variable has already been defined, the tag is ignored.

In the code above, useraccess is given an default value of "public". If the user has logged on then this initial value will be replaced with the value returned by the login query.

<!doctype html public "-//IETF//DTD HTML 3.2//EN">
<title>My First Forum</title>
<meta name="Generator" content="HTMLed32 Version 2.0a">
<meta name="Author" content="Andrew Shatwell">
<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="469" height="64">

Standard HTML to display the background image and My First Forum logo.

<CFIF ListFindNoCase(ForumDetails.ReadAccess, useraccess, ",") eq 0>
  <font face="Verdana, Arial" color="#800000">You do not have permission to view this group.</font>
  <p><a href="board.cfm">Return to main Bulletin Board</a>

We use the ListFindNoCase function again. This time to test if the user belong to a usergroup that has permission to read this forum.

If the user does not have permission to view this forum then display a relevant message.

Otherwise . . .

<CFQUERY NAME="ListArticles" DATASOURCE="#MyDatabase#">
  SELECT * FROM tblArticles WHERE GroupID= #forum# AND ThreadID = #ThreadID# ORDER BY link;

<CFIF ListArticles.recordcount eq 0><CFLOCATION URL="openforum.cfm?forum=#forum#"></CFIF>

The ListArticles query gets all the articles for this thread and sorts them so that replies to messages all string together. The fields returned by the query are:

<table cellpadding="0" cellspacing="0" border="0" width="95%">
<font size="2"><a href="board.cfm">Main Board</a><br></font>
  <img src="../images/tline.gif" width="12" height="12" border="0" alt="">
  <font size="2"><b>
    <a href="openforum.cfm?forum=#forum#">#ForumDetails.GroupName#</a></b></font>
<font color="#000080">
  <spacer size="12" type="horizontal">
  <img src="../images/tline.gif" width="12" height="12" border="0" alt="">
<font size="1" face="Verdana, Arial">
  <CFOUTPUT QUERY="ListArticles">
    <spacer size="24" type="horizontal">
    <CFIF log eq 1>
      <CFIF ListArticles.Posted gt login.LastLogin>
        <font color="##ff0000">
        <font color="##caca00">
    <a href="###ListArticles.ArticleID#">#left(ListArticles.message,30)# . . .</a>

This code creates a branch structure showing the relationship between all the messages within the thread. If the user has logged on, new messages are marked with two red stars (**). Old messages are shown with two yellow ones (**).

The link field contains a list of all the message IDs that directly preceded the current one. By sorting on this field, replies to articles are grouped under their specific parent message.

<td align="right" valign="top">
  <font size="2"><i>
    <CFOUTPUT><a href="openthread.cfm?forum=#forum#&ThreadID=#ThreadID#"></CFOUTPUT>Refresh screen</i>
<table border="0" width="95%">
<tr bgcolor="#D5E6E1">
  <td NOWRAP width="18%" valign="top">
    <FONT SIZE="1" face="Verdana, Arial" color="#000080">Name</font></td>
  <td valign="top" width="82%">
    <FONT SIZE="1" face="Verdana, Arial" color="#000080">Post</font></td>

<CFOUTPUT QUERY="ListArticles">
  <tr<CFIF ListArticles.CurrentRow MOD 2 eq 0> bgcolor="##f7f7f7"</CFIF>>
    <td align="left" valign="top">
      <FONT size="2" face="Verdana, Arial" ><b>#ListArticles.UserName#</b></td>
    <td><a name="#ListArticles.ArticleID#">
      <FONT SIZE="1" face="Verdana, Arial" color="##000080">
      <img src="../images/posticon.gif" width="14" height="11" border="0">
      Posted on #dateformat(ListArticles.Posted,"dd-mm-yy")#&nbsp;#timeformat(ListArticles.Posted,"h:mm tt")#
      <CFIF ListFindNoCase(ForumDetails.WriteAccess, useraccess, ",") neq 0>
        <a href="ReplyTo.cfm?articleID=#ArticleID#">Reply</a>
        <CFIF log eq 1><CFIF ListArticles.UserEmail eq login.email>
          <a href="Cancel.cfm?articleID=#ArticleID#">Cancel</a>
      <FONT SIZE="2" face="Verdana, Arial">

<spacer size="600" type="vertical">


Examining the code between the <CFOUTPUT>. . .</CFOUTPUT> tags, you will see a reference to ListArticles.CurrentRow.

Currentrow is property of all queries in Cold Fusion and returns the number of the row currently being processed by CFOUTPUT. We use this value in the above example to shade every second row of the table.

As the CFOUTPUT statement cycles through the query, two conditions are tested for each message. The first one checks if the user is allowed to post messages to this group. If true, then a Reply to message link is created.

The second CFIF statement compares the user's email address with the message author's. If they match then a Cancel message link is shown, enabling the user to delete their own messages.

Back to Opening a group, or forward to Posting a message - part 1

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