Building a Forum with Dreamweaver – Part 1: Displaying Messages
The topic messages will be displayed in the view_message.php page. The page layout is already created using
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.
To create the message list, do the following:
- Create an advanced recordset that retrieves information from two tables and filters it by the topic ID received as a URL parameter.
- Display the user name and a thumbnail of the profile photo.
- Display the message details.
- Use conditional regions to control the output.
First, you must create the advanced recordset. This recordset will have to perform a join between the
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:
- In the Bindings tab, click the Plus (+) button. Select Recordset (Query) from the pop-up menu.
- In the simple recordset configuration dialog box, enter rsMessages as the recordset name.
- From the Connection pop-up menu, select the connForum database connection.
- In the Table pop-up menu, select the
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.
Define the join between the
user_usrtables. Because you cannot define it in the simple recordset window, click the Advanced button in the Recordset dialog box.
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.
You have to change this code in order to perform the join. Place the cursor after the
message_msgtable name and enter the following code:
LEFT JOIN user_usr ON idusr_msg = id_usr
This is all it takes to create the query.
Review the completed dialog box (it should look like Figure 33) and click OK to close it.
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.