Managing relational tables has always been a struggle for both fledgling young web developers and grizzled old salts alike. Luckily for everyone who needs to link database tables, Data Bridge simplified the process, making it easy for just about everyone.
In this tutorial we're going to teach you what you need to do, and why, when it comes to using Data Bridge to manage your relational database tables.
We're going very easy on this one, and we're creating a basic music album site. You might want to rush right in with your own database and site, but we suggest following the tutorial to ensure you have the foundations needed.
- A dynamic site set up within Dreamweaver
- A blank database
- Dreamweaver CS3 or later
- Data Bridge installed and activated in Dreamweaver
- The Blue Sky Music database files, which can be downloaded here blue_sky_music.zip
The first step in this long journey is creating a database with some basic data. This will give us a central point to build our application around.
We're using the classic WebAssist staple; the Blue Sky Music database.
- Download the Blue Sky Music zip file
- Extract the files to an easily accessable directory
- Open your MySQL database manager
- Open the blue_sky_music.sql file
- Copy the contents of the file
- In your blank database, run the Blue Sky Music SQL query
- Create a Connection in your Dreamweaver site to the newly populated database
Alternatively, you can use the Import feature if your SQL manager supports it.
Now that we have this database set up, we can start making the files needed to work within our database.
To use the data we just added to our database, and to manage these relational tables, we're going to need Insert and Update pages. Just so we cover everything, we'll create the Results and Detail pages, too.
- Click WebAssist > Database > DataAssist Pages
- Use New From Blank as the Application Type. We're going pretty custom on this.
You CAN select a design, but for the sake of this tutorial, we're going to stick with Basic
- Make sure the connection to the blue_sky_music database is selected
- Select the items table
- Make sure ItemID is the Key Column
- Click the Manage Pages tab
- Click the Add Pages ( + ) button
- Select Insert
- Click OK
- On the Insert Page dialog, click the Add Columns ( + ) button
- Select the ItemName, ItemShortDesc, ItemLongDesc, ItemPrice, and ItemSKU columns
These columns are selected just so we have a little something to work with
- Click OK
- Click the Add Pages ( + ) button
- Select Update
- Click OK
- We're basically making the exact same page as Insert, only for Update
- On the Update Page dialog, click the Add Columns ( + ) button
- Select the ItemName, ItemShortDesc, ItemLongDesc, ItemPrice, and ItemSKU columns
Just like before, these columns are selected just so we have a little something to work with
- Click OK
- Click the Add Pages ( + ) button
- Select Results
This page is so you can easily view newly added and previously existing entries in your database
- Click OK
- On the Results Page dialog, click the Add Columns ( + ) button
- Select the ItemName, ItemShortDesc, ItemLongDesc, ItemPrice, and ItemSKU columns
- Click OK
- Click the Add Pages ( + ) button
- Select Details
This page is so you can view individual entries
- On the Details Page dialog, click the Add Columns ( + ) button
- Select the ItemName, ItemShortDesc, ItemLongDesc, ItemPrice, and ItemSKU columns
- Click OK
- Click Finish
- Click OK without saving the preset
- Save everything
Now that your pages are made, we're going to go ahead and update your Insert page to include music genre information. This will be the two sides of the linked databases: genres and items. Each item will be able to have multiple genres attached to it, and each genre will be connected to all of its related items.
Step 1: Create an area to hold the genre list
- On the Insert page, switch to Split view
- Select the last text box on the insert form in the design side of the view
- On the code side of the view, find the div with the class "lineGroup" that's containing the text box
Each DataBridge Application type can create the divs used in the page code a little diffferently. If you've used another Application type, the class name in the above div might be slightly different..
- Create a new div after the above mentioned lineGroup div. You can enter it manually, or paste in the following code:
This is going to create a new container for the checkbox area. The lineGroup class contains the data for how the div is being displayed
<div class="lineGroup">
</div>
- Add the following code right after the closing quotation mark of the class in the div we just created:
This will create a CSS style that gives the div a width of 600 on the page and hides all overflow
style="width:600px;overflow:hidden;"
- Now we're going to set a little label for the div we just created so people know it's a list of genres. Enter the following code at the end of your opening div tag:
- Now we need to create a span to hold the checkbox we're going to use for each genre. Enter the following code right after the <br> tag you just entered above:
This span will house the checkbox that will be used for each genre, as well as the label for each genre so we can repeat the span as many times as needed to display every available genre. This saves us having to manually enter each one.
- Last but not least, add the following style to the opening span tag:
This style will make each checkbox/ genre label combo in its own little container that is 200 pixels wide, and aligns them to the left. This will show the genre list in 3 columns, with as many rows as needed.
style="width:200px;float:left;"
- Save your page
At this point your entire div should look like this:
<div class="lineGroup" style="width:600px;overflow:hidden;">
Genres:
<br />
<span style="width:200px;float:left;">
</span>
</div>
Step 2: Add a checkbox to the genre list area
- Click your cursor in the span tags we created above
- Click Insert > Form > Checkbox from the menu bar
- Enter genres as the ID
- Set the Style to No label tag
- Click OK
- Click on your newly added checkbox
- In the Properties panel, enter 1 as the Checked Value for the checkbox
- Save your page
Step 3: Create a Recordset for genres
- In the menu bar, click Window > Bindings
- In the Bindings window, click the Add Binding ( + ) button
- Select Recordset (Query)
- Make sure the Recordset dialog is set to Advanced mode by clicking the Advanced... button
- Enter rsGeneres as the name of the Recordset
- Make sure the connection to the blue_sky_music database is selected
This will populate the Database items box with everything in your database
- Expand the Tables list
- Select genres from the expanded tables
- Click the SELECT button
This will add the following SQL query to the SQL box, which pulls all available genres from the genre list in the database:
- Click the OK button to add the Recordset to your page
- Save your page
Step 4: Make the checkbox dynamic
- In Code view, find the genre checkbox that we created earlier
- Select the 1 that we set as the value earlier
- Enter the following code in the place of the current 1 value of the checkbox so the relational tables know the selected GenreID
This line of code will give the checkbox a value based on the ID for each genre stored in the database, for as many genre IDs exist. These IDs are being pulled from the database with the help of our handy little rsGenres recordset.
<?php echo $row_rsGenres['GenreID']; ?>
- After the checkbox field, enter the following code to show the appropriate genre's name next to the checkbox
This pulls the genre name associated with the above GenreID that's stored in the database. This name is being pulled from the database with our rsGenres recordset
<?php echo $row_rsGenres['GenreName']; ?>
- At this point your entire div should look like this:
<div class="lineGroup" style="width:600px;overflow:hidden;" >
Genres:
<br />
<span style="width:200px;float:left;">
<input name="genre" type="checkbox" id="genre" value="<?php echo $row_rsGenres['GenreID']; ?> " />
<?php echo $row_rsGenres['GenreName']; ?>
</span>
</div>
- Save your page
Step 5: Repeat the checkbox for each genre
- In code view, select the span that goes around your checkbox
- In the Server Behaviors panel, click the Add Server Behavior ( + ) button
- Select WebAssist > DataAssist > Repeat Selection
- Select rsGenres for the Recordset field
- Select All records for the Repetitions field
- Click OK
This applies the Repeat Selection Server Behavior to the checkbox, and will show as many checkbox/ genre labels as there are in the database
- Save your page
Step 6: Apply 'Insert Multiple Records' to the genre checkboxes.
- From the Behaviors window, select WebAssist > DataAssist > Insert > Multiple Record Inserts.
- For the 'Repeated form:' selection, make sure 'Repeat Selection (rsGenres, All records)' is chosen.
- Use the 'blue_sky' connection and the 'itemgenres' table.
- Chose your results page for the 'Go to' option.
- Click on the 'Bindings' tab.
- Select the column 'ItemGenreItemID', click the lightning bolt, and choose the Session variable 'WADA_Insert_items'. The data type is Numeric.
- Select the column 'ItemGenreGenreID, click the lightning bolt, and chose the form item 'genres'. (Your form may be named something like 'Insert_Basic_Default'.) The data type is Numeric.
- Click Finish.
- Save your page.
It's the Update page's turn to get the genre list treatment. This process is exactly the same as on the Insert page.
Step 1: Create an area to hold the genre list
- On the Insert page, switch to Split view
- Select the last text box on the insert form in the design side of the view
- On the code side of the view, find the div with the class "lineGroup" that's containing the text box
Each DataBridge Application type can create the divs used in the page code a little diffferently. If you've used another Application type, the class name in the above div might be slightly different..
- Create a new div after the above mentioned lineGroup div. You can enter it manually, or paste in the following code:
This is going to create a new container for the checkbox area. The lineGroup class contains the data for how the div is being displayed
<div class="lineGroup">
</div>
- Add the following code right after the closing quotation mark of the class in the div we just created:
This will create a CSS style that gives the div a width of 600 on the page and hides all overflow
style="width:600px;overflow:hidden;"
- Now we're going to set a little label for the div we just created so people know it's a list of genres. Enter the following code at the end of your opening div tag:
- Now we need to create a span to hold the checkbox we're going to use for each genre. Enter the following code right after the <br /> tag you just entered above:
This span will house the checkbox that will be used for each genre, as well as the label for each genre so we can repeat the span as many times as needed to display every available genre. This saves us having to manually enter each one.
- Last but not least, add the following style to the opening span tag:
This style will make each checkbox/ genre label combo in its own little container that is 200 pixels wide, and aligns them to the left. This will show the genre list in 3 columns, with as many rows as needed.
style="width:200px;float:left;"
- Save your page
At this point your entire div should look like this:
<div class="lineGroup" style="width:600px;overflow:hidden;">
Genres:
<br />
<span style="width:200px;float:left;">
</span>
</div>
Step 2: Add a checkbox to the genre list area
- Click your cursor in the span tags we created above
- Click Insert > Form > Checkbox from the menu bar
- Enter genres as the ID
- Set the Style to No label tag
- Click OK
- Click on your newly added checkbox
- In the Properties panel, enter 1 as the Checked Value for the checkbox
- Save your page
Step 3: Create a Recordset for genres
- In the menu bar, click Window > Bindings
- In the Bindings window, click the Add Binding ( + ) button
- Select Recordset (Query)
- Make sure the Recordset dialog is set to Advanced mode by clicking the Advanced... button
- Enter rsGenres as the name of the Recordset
- Make sure the correct connection is selected
This will populate the Database items box with everything in your database
- Expand the Tables list
- Select genres from the expanded tables
- Click the SELECT button
This will add the following SQL query to the SQL box, which pulls all available genres from the genre list in the database:
- Click the OK button to add the Recordset to your page
- Save your page
Step 4: Make the checkbox dynamic
- In Code view, find the genre checkbox that we created earlier
- Select the 1 that we set as the value earlier
- Enter the following code in the place of the current 1 value of the checkbox so the relational tables know the selected GenreID
This line of code will give the checkbox a value based on the ID for each genre stored in the database, for as many genre IDs exist. These IDs are being pulled from the database with the help of our handy little rsGenres recordset.
<?php echo $row_rsGenres['GenreID']; ?>
- After the checkbox field, enter the following code to show the appropriate genre's name next to the checkbox
This pulls the genre name associated with the above GenreID that's stored in the database. This name is being pulled from the database with our rsGenres recordset
<?php echo $row_rsGenres['GenreName']; ?>
- At this point your entire div should look like this:
<div class="lineGroup" style="width:600px;overflow:hidden;">
Genres:
<br>
<span style="width:200px;float:left;">
<input name="genre" id="genre" value="<?php echo $row_rsGenres['GenreID']; ?> " type="checkbox">
<?php echo $row_rsGenres['GenreName']; ?>
</span>
</div>
- Save your page
Step 5: Repeat the checkbox for each genre
- In code view, select the span that goes around your checkbox
- In the Server Behaviors panel, click the Add Server Behavior ( + ) button
- Select WebAssist > DataAssist > Repeat Selection
- Select rsGenres for the Recordset field
- Select All records for the Repetitions field
- Click OK
This applies the Repeat Selection Server Behavior to the checkbox, and will show as many checkbox/ genre labels as there are in the database
- Save your page
Our next step is simply to remove the redirect functionality that was created when the pages were created. The Manage Relational Table Server Behavior is going to handle this later on, and we don't need any conflicts.
Step 1: For the Insert page
- Open the Insert page
- Open the Server Behaviors panel
- Double click on the 'Insert Record (items)' Server Behavior to open it
- Clear the 'Go to' field in the 'After Insert' section
- Now write down the 'Store as' value under the 'Save Inserted ID in Session' section
This value is the name of a Session variable that was created to store the ID of the record that was just inserted. Later, the Manage Relational Table will use this to know which record is being talked about in regards to the relationship between the item being inserted and the genres with which it's associated
- Click OK
- Save your page
Step 2: For the Update page
- Open the Update page
- Open the Server Behaviors panel
- Double click on the 'Update Record (items)' Server Behavior to open it
- Clear the 'Go to' field in the 'After Insert' section
- Click OK
- Save your page
For this step, we need to add a variable to each page to allow the Manage Relational Table Server Behavior to know which itemis either being inserted, or updated. To do this, we need a session variable on the Insert page to hold the item being inserted, and a URL variable on the Update page to hold the ID of the item being updated.
Step 1: For the Insert page
- Open the Insert page
- On the Bindings panel, look for a Session variable named the same as the value we wrote down when looking at the insert server behavior
In this case, the value should be 'WADA_Insert_Items', but this value will change in the future when you do your own project
- If it exists, it was created by the Insert server behavior, and you can skip the rest of this section, if not, click the Add Binding ( + ) button
- Select Session Variable
- On the Variable dialog that appears, enter the value we wrote down from the Insert server bahavior earlier in the Name field
In this instance, the name will be 'WADA_Insert_Items', but this WILL change when you are doing your own project in the future
- Click OK
- Save your page
Step 2: For the Update page
The reason we are adding this update variable to the page is to prepopulate the checkboxes we added earlier with the correct genres that are available to us.
- Open the Update page
- In the Server Behaviors list, double click the 'Recordset(WADAitems)' Server Behavior to open it
- Under the variables list, click on 'ParamItemID'
- Look at the values for 'ParamItemID' and find the Run-Time Value
- Look for the text within the single quotes of the $_GET text. An example is $_GET['thistexthere'].
In this case the value will be ItemID. This value is the current ID of the record being updated. This will be used in the Manage Relational Table later to create the relationship between the item being updated, and its associated genres
- In the Bindings panel, look for a URL variable named the same as the value we wrote down when looking at the Recordset(WADAitems) server behavior
In this case, the value should be ItemID, but this value will change in the future when you do your own project
- If it exists, it was created by the Update server behavior, and you can skip the rest of this section, if not, click the Add Binding ( + ) button
- Select URL Variable
- On the Variable dialog that appears, enter the value we wrote down from the Update server bahavior earlier in the Name field
In this instance, the name will be ItemID, but this WILL change when you are doing your own project in the future
- Click OK
- Save your page
It's time to get to the heart of this tutorial, the Managing Relational Table server behavior. This section will walk you through the proper set-up and configuration of MRT.
Step 1: Insert the Manage Relational table Server Behavior
- Open the Update page
- On the Server Behavior panel, click the Add Server Behavior ( + ) button
- Select WebAssist > DataAssist > Manage Relational Table
Step 2: Database and Redirect
This will redirect back to the Details page after successful update and send the ItemID as the update URL variable data on redirect so you can see your newly updated item.
- On the Manage Relational Table dialog, set the Relational table field to 'itemgenres'
- Click the Browse folder button next to the 'Go to' field
- Select the Details page
- Click the 'Parameters...' button
- Under the Name column, enter the name of the URL variable that either we created, or the Update Server Behavior created
This variable is used by the Details page to know what product to display. Remember, in this case it's 'ItemID', but that will change depending on your application
- Click in the Value column
- Click the Dynamic Data (lightning bolt) button
- Expand the URL field in the Field list
- Select the URL variable that either we created, or the Update Server Behavior created
Remember, in this case it's 'ItemID', but that will change depending on your application
- Click OK
- Click OK again
- Click Choose
This is how your wizard should appear on this step:
- Click Next
Step 3: Main Table Join
This is going to enter the updated item's ID into the relational table's 'ItemGenreItemID' field for each genre the item has.
- Set the Foreign key column value to 'ItemGenreItemID'
In this case, 'ItemGenreItemID' is being used, but in future cases, you're going to select the Foreign key column value of the main table being used. The Main table will be the actual item that you are attaching properties to. The properties of the item themselves will be the Options table
- Set the Data type field to Numeric
- For the Key value field, click the Dynamic Data (lightning bolt) button
- Expand the URL field in the Field list
- Select the URL variable that either we created, or the Update Server Behavior created
Remember, in this case it's 'ItemID', but that will change depending on your application
- Click OK
This is how your wizard should appear on this step:
- Click Next
Step 4: Options Table Join
This will enter the genre ID for each genre the item is related to.
- Set the Foreign key column value to 'ItemGenreGenreID'
In this case, 'ItemGenreGenreID' is being used, but in future cases, you're going to select the Foreign key column value of the options table that stores the possible properties of the Main table
- Set the Data type field to Numeric
- For the Options formfield field, Select 'genres' in Repeat Selection (rsGenres, All records)
This is how your wizard should appear on this step:
- Click Next
This is how your wizard should appear on this step:
- Click Finish
- Save your page
And... *dusts off hands* The Update page is finished.
Well done, my dear friend. You're my favorite web developer, you know that? *Shh* Don't tell anyone, though. It'll be our secret.
You now have the power inside of you to utilize the Manage Relational Table Server Behavior on your own site, so get cracking!
Peterson Design Studio - jefferis: 10 Years, 6 Months, 3 Weeks, 3 Days, 19 Hours, 50 Minutes ago
This is very technical, but a little short on the "why" of each step and what it is designed to accomplish.
: 10 Years, 6 Months, 1 Hour ago
I'm using Dreamweaver CC and "On Step 2: Add a checkbox to the genre list area" I do not get the dialog box asking for the checkbox ID, Label and style. On the properties panel at the botton of the window there is no ID field.
Thanks
Jason Byrnes: 10 Years, 5 Months, 4 Weeks, 1 Day, 22 Hours, 40 Minutes ago
Adobe have removed that Dialog box in DW CC. In the property Inspector, you should enter genres as the Name, it will use the name you enter for both the ID attribute and the Name attribute.