Section 21.2. Adding Dynamic Information

21.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 ways to add information. Start in the document window by clicking the spot where you wish to add the dynamic information. Then do one of the following:

  • Choose Insert Application Objects Dynamic Data Dynamic Text.

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

Figure 21-6. The Dynamic Data button (circled) on the Insert bar's Application tab lets you insert a variety of dynamic datafrom form fields filled in with information retrieved from a database, to a complete table based on a recordset.

Either way, the Dynamic Text window appears (see Figure 21-7), listing the recordsets on the current page. Click the + sign button next to the recordset from which you wish to get information from. This expands to show all columns retrieved in that recordset. 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.

Figure 21-7. 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.


Note: Dynamic Text is a bit of a misnomer. This tool can also insert dates, numbers , and dollar valuesnot just text.

The format menu lets you format the data, like making a date appear as January 17, 2005 . Formatting is discussed in depth in the "Formatting Dynamic Information" section below.

21.2.1. The Bindings Panel

The Bindings panel (Figure 21-8) provides two other ways to put data from a recordset onto a page. (It's called Bindings because the panel provides a mechanism to "bind" or attach data from a database to a particular spot on a Web page.) Recordsets appear in the Bindings panel of the Application panel group . To open this panel, choose Window Bindings or press Ctrl+F10 ( -F10).

Figure 21-8. 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. Dreamweaver uses these as part of the Recordset Navigation Status server behavior (see Section 21.4) to display just a handful of results from a much larger recordset, so you can display a message like "items 1120 out 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 windowinto a paragraph or table cell , for example.

After adding dynamic information to a page, it looks something like {rsProducts. prodName} . The information in braces 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 when you use Dreamweaver's Live Data view, as described on Section 21.5.)

21.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 includes many different formatting options for numbers, dates, and text. You can choose a formatting option when using the Insert Dynamic Text window (Figure 21-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 [ -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 21-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.


Note: PHP users' tip : Dreamweaver 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 http://dmxzone.com/ShowDetail.asp?NewsId=4138, which adds formatting options for dates, currency, and text.

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.

Figure 21-9. 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 you're adding one of those messages to a page, applying the Encode Server. HTMLEncode format ensures that Web browsers don't render any code in a message as part of your page. Instead, any HTML in that dynamic text appears 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 taga situation that could make your page not appear at all!

21.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 Delete, and so on.

If you remove all 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 on Section 21.1.8. Even though you may not display any dynamic information on the page, if a page contains a recordset, it must still communicate with the database server, slowing down your pages.



Dreamweaver 8[c] The Missing Manual
Dreamweaver 8[c] The Missing Manual
ISBN: 596100566
EAN: N/A
Year: 2006
Pages: 233

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net