![]() |
< Day Day Up > |
![]() |
24.3 Advanced Server BehaviorsIn addition to the server behaviors described already, you'll find two other sets of behaviors that come in handy on dynamic Web pages.
24.3.1 Recordset PagingThis set of five different behaviors lets you add links for jumping to different records in a recordset (straight to the last record, for example). In fact, Dreamweaver makes use of these same behaviors as part of its Recordset Navigation Bar object. You'll use these for moving through a long list of records, like a complete listing of products in a database. To begin, add a recordset to a page. It should contain multiple records, since jumping to the next record when there's only one doesn't make much sense. The page could also contain a repeating region, so that several records appear. You can add the recordset paging server behaviors from the Server Behaviors panel, or from the new recordset paging menu on the Application tab of the Insert Bar (see Figure 24-7).
NOTE
In ColdFusion, ASP.NET, and PHP, you'll see the word Page instead of Record in this example and the following ones. For example, Move to First Page instead of Move to First Record.
You can create your own recordset navigation controls using the recordset paging server behaviors.![]() Using any of the first four behaviors involves the same steps:
The Move to Specific Record behavior works a bit differently. It doesn't add a link to the page; it simply forces the page to display a particular record when the page is requested. It does this by looking for a URL parameter that specifies a particular record in the recordset. In general, this isn't a good approach, since it requires the database server to retrieve many records just to display a single item from the database, which is a waste of server resources. On a busy site, that could mean a slowdown. You're better off creating a detail page (Section 22.7), which simply retrieves one record from the database. 24.3.2 Show Region Server BehaviorsAt times, you'll want to display different information on a page based on the results of a recordset. For example, if a visitor searches your site's database of products for a product you don't sell, the search results page should say something like, "Sorry, we don't carry alligator skin bicycle seats." But if someone searches for a product you do sell, then the page should present the relevant details for that product. The Web page displays different text depending upon whether the search item was in the recordset. Dreamweaver provides three sets of server behaviors that let you display any selection of HTML based on the results of a recordset.
The Show Region server behaviors are available on both the Application tab of the Insert bar and the Server Behaviors panel.![]() You can use these behaviors to show any selected object on the page梐 paragraph of text, an image, a table, and so on. Your page can contain any combinations of these behaviors, and you can use any behavior two or more times to display multiple areas of a page. For example, maybe you'd like two things to appear when the recordset successfully retrieves a record: a graphic in the page's sidebar and a message in the main area of the page. You'd apply a Show If Recordset Is Not Empty server behavior to both selections of HTML (the graphic and the message). You'll often use these behaviors in pairs. For example, a search results page should include both the "Show If Recordset Empty" behavior to display a "no results" message, and a "Show If Recordset Not Empty" behavior to display the search results. To apply any of these behaviors:
NOTE
The last four behaviors桽how If First Page, Show If Not First Page, Show If Last Page, and Show If Not Last Page梬ork only on pages that also have one of the recordset paging server behaviors applied.
Regardless of which of the Show Region server behaviors you apply, there's only one option to choose: the recordset whose results control the display of the region.![]() After applying one of these behaviors to a selection of HTML, a gray line appears around the selection, and a gray tab appears bearing the words "Show If." That's the area that will appear if the given recordset condition is met (for example, if the page is displaying the last record of the recordset). To remove a Show Region server behavior, select its name in the Server Behaviors panel and click the - button (or press the Delete key). Doing so removes the gray tab and outline. Now the affected HTML will appear regardless of the recordset results. NOTE
PHP note桝n extension called PHP Show If Recordset Field Condition Is True (available for free on the Macromedia exchange) lets you display part of a page when a field from a recordset matches a certain condition. Suppose, for example, that you have a products database with a field that records whether a particular item is for sale. If the item is indeed for sale, then you can use this behavior to display a large "For Sale" graphic on the product's detail page. |
![]() |
< Day Day Up > |
![]() |