Populating Page Layouts Dynamically

Up to this point in the book, most of the dynamic data you have displayed has been simpleusually a single item. But now you are going to output an entire country profile, comprising multiple kinds of data. To accomplish this, you'll intersperse dynamic output with the static HTML code you inserted in the previous task.

  1. Position the cursor just after Country Name, and in the Bindings panel, expand Recordset(rs_countries) and click CountryName, and click Insert. In the document window, delete the placeholder words Country Name, leaving just the dynamic text.

    This causes the country name in the selected record to appear formatted as the redefined <h2> element.

    graphics/10fig18.gif

  2. Position the cursor after the colon in World Region:, and press Shift+Enter (Windows) or Shift+Return (Macintosh) to insert a line break. Select World Region: and click the Bold button in the Property inspector.

    You'll add the dynamic data in the line just beneath World Region, and the bolding distinguishes the category name from the data that will appear there.

    The line beneath World Region should not be bold.

    graphics/10fig19.gif

  3. One at a time, format the remaining four categories in the same manner, adding a line break and bolding only the first line.

    You've now made room for all of the dynamic data.

    graphics/10fig20.gif

  4. One at a time, bind region to the line beneath World Region; bind description beneath Description; imageALT beneath Image Caption; population beneath Population; and country_currency beneath Local Currency.

    Laying out pages with dynamic data is quite easy.

    graphics/10fig21.gif

  5. Save, upload, and test the file.

    Not bad for a beginning, but there are several issues that you still need to work out.

    graphics/10fig22.gif

    You might be wondering why Canada showed up as the country. The reason is that when you created your query, Dreamweaver set the default URL parameter to 1 (in both ASP and ColdFusion), and Canada is the country in the database with that value. If Dreamweaver had not added that default value, then you would have seen an error message, because the query depends on a URL parameter where none existed. Had you accessed this page from profiles.asp, of course, there would have been a URL parameter.

    The World Region is listed as 1, which is not terribly helpful. Why does Canada have a world region of 1, rather than something meaningful, such as North America? This has to do with the structure of the database. Remember, relational databases often have foreign keys, rather than actual data in their fields. That's what's happening in this case. Because most countries share continents with other countries, I created a separate table for continents in the database, and used the key (unique ID) in tbl_region as a foreign key in tbl_country. The result is that that key valuein this case, 1is showing on the page, rather than the region name. To fix this, you'll need to look up the region name associated with 1 in tbl_region.

    Finally, the population figure is listed as 30007094, but it would be easier to read as 30,007,094. You'll use a built-in function to format this number correctly.