Create a guestbook with DreamweaverMX (2)
Author:Eve Cole
Update Time:2009-05-31 21:07:17
We mentioned earlier that to ensure the normal display of messages, we must display messages only when there are messages. If there are no messages, "No messages yet" will be displayed. So how do you do this in DW MX? ? Here, we have to learn a new server behavior show region, which displays different information based on the information in the library.
Let’s talk about its basic concept first. Take the message content above as an example: if the content of my message is empty, what will be displayed; if the content of the message is not empty, what will be displayed. As shown in Figure (7-9).
7-9
After selecting the entire message content table, use Application-->Server Behaviors-->Show Region-->Show Region If Recordset Is Not Empty (when the record set is not empty), that is, display this form when the message content is not empty. Having said that, I have to talk about several other server behaviors.
Show Region If Recordset Is Empty (if the recordset is empty): When the recordset is empty, display the selected region.
show Region If Recordset Is Not Empty (if the recordset is not empty): When the recordset contains records, displays the selected region.
Show Region If First Record: Displays the selected region when it is the first record in the record set.
Show Region If Not First Record: Displays the selected region when there is not the first record in the record set.
Show Region If Last Record: Displays the selected region when it is the last record in the record set.
Show Region If Not Last Record: Displays the selected region when there is not the last record in the record set.
Click it and a dialog box will appear as shown in Figure (7-10).
7-10
In this dialog box, select the record set corresponding to this behavior. On this page, we only created one record set named guestbook. The effect after applying the server behavior is shown in Figure (7-11).
7-11
In order to prevent errors when there is no message content, here we also need to use the Show Region If Recordset Is Empty (when the record set is empty) behavior and apply it to the "No message yet" table. The final effect is as shown in the figure (7-12) shown.
7-12
Next, let us improve it by inserting some small tables into the large table that displays messages, arranging them, and inserting related pictures (here are the most common small pictures on the Internet. :)), as shown in Figure (7- 13) shown. Here are some of the most basic Dreamweaver table skills, see other chapters in this series of tutorials for details.
7-13
What you need to do now is to drag the data in the database to the corresponding table. For example, drag the user name to the cell after the name. The message content should be placed in the cell after the message content. Remember to drag f_name to the post In the front, drag f_time to the post in the back, so that when displayed, it becomes "XX published in XX". See Figure (7-14).
7-14
There is a small bug here, that is, the message we display cannot be formatted. That is, you will find that no matter how many carriage returns there are in your message, it will not break when displayed, and there are more than two spaces. will become a space. This problem can be solved using the spdformat.mxt plug-in (click here to download the plug-in!). After installing the plug-in, the method is as shown in Figure (7-48). Both message content and webmaster replies must use this plug-in.
7-48
Maybe people are asking again, how do I do those OICQs and the like in my database. As for this, I don’t know if you know the alt attribute of the img tag in HTML, that is, when the mouse is moved up, the corresponding description text is displayed. Here, we dynamically bind it to the picture accordingly. As for the homepage address, just click it and connect to the corresponding address. For the email address, click it and open Outlook to send a message to the person who left the message.
The specific aspects are shown in Figure (7-15).
7-15
There is a sequence here. First select the OICQ picture, and then select the corresponding data set from the record set on the right (here, select the field (f_oicq) that stores the OICQ number in the database, and then select from the Bind To: drop-down menu. img.alt, which is the img tag attribute we talked about earlier, and then click Bind later. If the binding is correct, the same color as the previous record set will be generated to indicate that a server behavior is applied here. As shown in Figure (7-16). Here we still need to beautify it.
7-16
Open the source code and design view, you will find that the stuff you just inserted is alt="<%=(guestbook.fields.item("f_oicq").value)%>" in the code, COPY this code and put it in it front, and change f_oicq to f_name (the name field of the poster in the database), so that its final code is alt="<%=(guestbook.fields.item("f_name").value)%> The OICQ number is <%=(guestbook.fields.item("f_oicq").value)%>", so when it is displayed, it will be "XX's OICQ number is XX". It is all dynamically bound. How great. ,Oh. .
7-17