Previous Section  < Day Day Up >  Next Section

22.2 Adding Dynamic Information

Once a recordset is created, it's a snap to add dynamic information to a Web page. In fact, Dreamweaver provides several techniques to go about it. Start in the document window by clicking the spot where you wish to add the dynamic information. Then do one of the following:

  • Choose InsertApplication ObjectsDynamic Text.

  • Click the Dynamic Data button in the Application tab of the Insert bar and select Dynamic Text from the menu (see Figure 22-6).

The Dynamic Data button on the Insert bar's Application tab lets you insert a variety of dynamic data梖rom form fields filled in with information retrieved from a database, to even a complete table based on a recordset.

Either way, the Dynamic Text window appears (see Figure 22-7), listing the recordsets on the current page. Pick the database column (also called Field) containing the information you wish to add to the page. You can pick only one column at a time, but you can repeat this process to add multiple columns to the page.


Dynamic Text is a bit of a misnomer. This tool can also insert dates, numbers, and dollar values梟ot just text.

The format menu lets you format the data, like making a date appear as January 17, 2004. Formatting is discussed in depth on the facing page.

After you select a database field to add to a page, Dreamweaver displays the necessary code in the Code field. This is the programming code that makes the data appear on the page. It's written in the programming language specified by the current server model.

22.2.1 The Bindings Panel

The Bindings panel (Figure 22-8) provides two other ways to put data from a recordset onto a page. Recordsets appear in the Bindings panel of the Application panel group. To open this panel, choose WindowBindings or press Ctrl+F10 (figs/command.jpg-F10).

A recordset listing in the Bindings panel includes the name of each column, plus three additional items: first record index, last record index, and total records. These can come in handy when you're only displaying part of a recordset, such as items 11?0 in a recordset of 149 items.

To add data from the Bindings panel to a page, click in the document window where you wish to insert the dynamic data. Then select the column you wish to add and click Insert. Or, faster yet, just drag a column's name from the Bindings panel directly into the document window梚nto a paragraph or table cell, for example.

After adding dynamic information to a page, it looks something like{ Name}. The information in brackets indicates the name of the recordset (rsProducts) and the name of the data column (prodName). (You can make real data appear instead of this code using Dreamweaver's Live Data view, as described in Section 22.5.)

22.2.2 Formatting Dynamic Information

Suppose a database includes a column for a product price, storing it as 8 or 10.99. But on your Web page, you want prices properly formatted with a dollar sign and two decimal places, like $8.00 or $10.99.

Dreamweaver MX 2004 includes many different formatting options for numbers, dates, and text. You can choose a formatting option when using the Insert Dynamic Text window (Figure 22-7). You can also apply, remove, or change a formatting option using the Bindings panel.

To set a format using the Bindings panel (Ctrl+F10), proceed as follows:

  1. In the document window, click the dynamic item you wish to format.

    A down-pointing arrow appears under the Format column in the panel.

  2. In the Bindings panel, click the down-pointing arrow under the Format column and select a formatting option from the menu (Figure 22-9).

    Pick an option that's appropriate to the selected piece of data: Currency formatting for the price of a product, for example. If you try to apply a formatting option that isn't appropriate for the selected item (Currency to a text description, say), the page may produce an error when previewed on the testing server.


To PHP users桪reamweaver doesn't include date, currency, or number formatting options for the PHP/MySQL server model. You can, however, find a free extension called PHP Server Formats at , which adds formatting options for dates, currency, and text.

The options shown here (for the ASP/VBScript server model) include a dizzying array of choices, including 19 date and time formats. One of them, "Encode - Server.HTMLEncode," may come in handy if your database stores HTML code. For example, maybe you've created a bulletin board whose messages are stored in a database. When adding one of those messages to a page, applying the Encode - Server.HTMLEncode format will ensure that Web browsers won't render any code in a message as part of your page. Instead, any HTML in that dynamic text will appear to visitors as code. Similarly, if there's any chance a data field might store a bracket like this <, the Encode formatting option prevents a Web browser from thinking that the opening bracket is the start of an HTML tag? a situation that could make your page not appear at all!

You can also format selected dynamic data just as you would other text on a page by applying CSS styles, headings, bulleted lists, and so on.

22.2.3 Deleting Dynamic Information

Dynamic information added to a page behaves like a single object. Just click to select it. You can also drag it to another location on the page, copy and paste it, remove it from a page by selecting it and pressing the Delete key, and so on.

If you remove all of the dynamic information from a page, and don't plan on using any information from the recordset, make sure you delete the recordset, too, as described in Section 22.1.8. Even though you may not display any dynamic information on the page, if a page contains a recordset, it still must communicate with the database server, slowing down your pages.

    Previous Section  < Day Day Up >  Next Section