Showcase and discover digital art at yex

Follow Design Stacks

Subscribe to our free newsletter to get all our latest tutorials and articles delivered directly to your inbox!

Building a Forum with Dreamweaver – Part 1: Displaying Messages

Displaying Messages

The topic messages will be displayed in the view_message.php page. The page layout is already created using

tags. You can change the existing styles and layout on the CSS panel.

The page displays the following for each message:

  • User name and avatar (profile photo) in the left section
  • Message subject, body, and date of posting in the center

    tags
  • Link to reply to the message

The layout is similar to what’s shown in Figure 30.

Layout for displaying messages

Figure 30. Layout for displaying messages

To create the message list, do the following:

  1. Create an advanced recordset that retrieves information from two tables and filters it by the topic ID received as a URL parameter.
  2. Display the user name and a thumbnail of the profile photo.
  3. Display the message details.
  4. Use conditional regions to control the output.

First, you must create the advanced recordset. This recordset will have to perform a join between the message_msg and user_usr tables.

Note: The SQL join is an operation that enables you to retrieve information from two or more tables that are related through a foreign key.

To create the recordset, follow these steps:

  1. In the Bindings tab, click the Plus (+) button. Select Recordset (Query) from the pop-up menu.
  2. In the simple recordset configuration dialog box, enter rsMessages as the recordset name.
  3. From the Connection pop-up menu, select the connForum database connection.
  4. In the Table pop-up menu, select the message_msg table.
  5. To retrieve messages in a particular topic, you must add a filter condition. In the Filter pop-up menu, select the foreign key to the topic table: idtop_msg. For the value to match, select URL Parameter from the pop-up menu. For the parameter name, enter id_top (the name specified when you created the topic link).

    The configured, simple Recordset dialog box should look like Figure 31.

    Configuring the rsMessages recordset

    Figure 31. Configuring the rsMessages recordset

  6. Define the join between the message_msg and user_usr tables. Because you cannot define it in the simple recordset window, click the Advanced button in the Recordset dialog box.

  7. Enter the SQL code in the SQL text area (see Figure 32). When switching from the simple dialog box to the advanced one, your settings will be preserved in the SQL code.

    Entering SQL code in the SQL text area

    Figure 32. Entering SQL code in the SQL text area

  8. You have to change this code in order to perform the join. Place the cursor after the message_msg table name and enter the following code:

    LEFT JOIN user_usr ON idusr_msg = id_usr

    This is all it takes to create the query.

  9. Review the completed dialog box (it should look like Figure 33) and click OK to close it.

    Completed Advanced Recordset dialog box

    Figure 33. Completed Advanced Recordset dialog box

The recordset is displayed in the Bindings tab. It contains fields from both tables. After having retrieved all necessary information from the database, it is time to put it to use and display it in the page.

Comments