End User Recipe: Mailing List Results Page

After the user selects his criteria on the search page, a list of resulting names appears on the Mailing List page. The Mailing List page allows the user to confirm the results and, if it is as expected, forward the list to the Send Mail page for emailing. Alternatively, the user can return to the Search Users page to modify the search.

The page is fairly straightforward and consists primarily of a table to hold the recordset data. A Repeat Region server behavior is used to display all the returned records. The recordset is constructed from a somewhat complex SQL statement based on the various session variables constructed in the Search Users page.

Note

This application does not include special handling should the search criteria return no results. You might consider such error handling as described in earlier recipes, such as Recipe 2: Employee Lookup.


Step 1: Implement Mailing List Design

Here's a straightforward page where a table-based layout for holding repeating rows of data is ideal:

  1. Create a page for the Mailing List recipe, either from a template or from the File > New dialog.

    graphics/book.gif In the MailMerge folder, locate the folder for your server model and open the mailing_list page there.

  2. In the content area of your page, create a header for the page and an area to hold both the returned search results.

    graphics/book.gif From the Snippets panel, drag the Recipes > MailMerge > Wireframes > Mailing List - Wireframe snippet into the Content editable region.

  3. Add labels and table cells to hold the mailing list information (name, email address, and access group) and links to the pages for sending email and searching again.

    graphics/book.gif Place your cursor in the row below the words MAILING LIST and insert the Recipes > MailMerge > ContentTables > Mailing List - Content Table snippet [r8-3].


    Figure r8-3.

    graphics/10fig03.jpg


  4. Save the page.

Step 2: Add Database Components

You've seen how the search criteria are placed into session variables for easy access in the Search Users page. Now we're ready to use those session variables to build a recordset of search results.

The SQL statement used in the recordset combines two tables Users and AccessGroups to accommodate searches either by individual or group. The session variables are incorporated into the SQL statement in different ways, depending on the server model. ASP and PHP users must establish SQL variables for each of the session variables addressed; ColdFusion users can access the session variables directly. However, in all versions, the SQL statement is constructed so that it filters results based on information entered in either of the search forms or both.

Note

To accommodate the different dialogs for the various server models, the steps are presented separately here and when necessary throughout this recipe.


For ASP

graphics/book.gif

If you're following our recipe, before you begin this step, copy the SQL code from the provided snippet. Right-click (Ctrl-click) on Recipes > MailMerge > SQL > Search Results ASP and select Copy Snippet from the context menu.


  1. From the Bindings panel, choose Add (+) and select Recordset (Query) from the list.

  2. In the Recordset dialog, choose Advanced.

  3. Enter an appropriate name for the recordset.

    graphics/book.gif Enter SearchResults in the Name field.

  4. Select the desired data source.

    graphics/book.gif Choose Recipes from the Connections list.

  5. In the SQL area, enter the following code:

     
     graphics/vb.gifSELECT * FROM Users Inner Join AccessGroups ON Users.UserAccess = AccessGroups.AccessGroupID WHERE UserFirstName LIKE 'FirstParam%' AND UserLastName LIKE 'LastParam%' AND UserEmail LIKE 'EmailParam%' OR UserAccess = AccessParam 
     

    Paste the copied code in the SQL area by pressing Ctrl-V (Command-V).

Now we'll add four separate variables, one for each of the session variables.

  1. In the Variables section, choose Add (+) to create a new variable.

  2. Enter the name for the variable.

    graphics/book.gif In the Name column, enter FirstParam.

  3. Enter a default value for the variable.

    graphics/book.gif In the Default Value column, enter %.

    The percent sign acts as a wildcard allowing matches with any value if no other value is available. Wildcards are used for three of the four parameters in this recordset to match the three form fields.

  4. Enter a run-time value for the variable.

    In the Run-Time Value column, enter Session("Search_First").

    graphics/book.gif In the Variables section, choose Add (+) to create a new variable.

  5. Enter the name for the variable.

    graphics/book.gif In the Name column, enter LastParam.

  6. Enter a default value for the variable.

    graphics/book.gif In the Default Value column, enter %.

  7. Enter a run-time value for the variable.

    In the Run-Time Value column, enter Session("Search_Last").

    graphics/book.gif In the Variables section, choose Add (+) to create a new variable.

  8. Enter the name for the variable.

    graphics/book.gif In the Name column, enter EmailParam.

  9. Enter a default value for the variable.

    graphics/book.gif In the Default Value column, enter %.

  10. Enter a run-time value for the variable.

    In the Run-Time Value column, enter Session("Search_Email).

    graphics/book.gif In the Variables section, choose Add (+) to create a new variable.

  11. Enter the name for the variable.

    graphics/book.gif In the Name column, enter AccessParam.

  12. Enter a default value for the variable.

    graphics/book.gif In the Default Value column, enter 0.

  13. Enter a run-time value for the variable.

    In the Run-Time Value column, enter Session("Search_Access").

  14. Click OK to close the dialog and insert the recordset.

For ColdFusion

graphics/book.gif

If you're following our recipe, before you begin this step, copy the SQL code from the provided snippet. Right-click (Ctrl-click) on Recipes > MailMerge > SQL > Search Results CFML and select Copy Snippet from the context menu.


  1. From the Bindings panel, choose Add (+) and select Recordset (Query).

  2. Switch to the advanced view of the dialog and enter an appropriate name for the recordset.

    graphics/book.gif Enter SearchResults in the Name field.

  3. Choose your data source.

    graphics/book.gif Select Recipes from the Data Source list.

  4. Enter a username and password if necessary.

  5. In the SQL area, enter the following code:

     
     SELECT * FROM Users Inner Join AccessGroups ON Users.UserAccess = AccessGroups.AccessGroupID WHERE UserFirstName LIKE '#Session.Search_First#%' AND UserLastName LIKE '#Session.Search_Last#%' AND UserEmail LIKE '#Session.Search_Email#%' OR UserAccess = #Session.Search_Access# 
     

    graphics/book.gif Paste the copied code into the SQL area by pressing Ctrl-V (Command-V).

  6. Verify your SQL in the Recordset dialog and click OK to close that dialog.

For PHP

graphics/book.gif

If you're following our recipe, before you begin this step, copy the SQL code from the provided snippet. Right-click (Ctrl-click) on Recipes > MailMerge > SQL > Search Results PHP and select Copy Snippet from the context menu.


  1. From the Bindings panel, choose Add (+) and select Recordset (Query) from the list.

  2. In the Recordset dialog, choose Advanced.

  3. Enter an appropriate name for the recordset.

    graphics/book.gif Enter SearchResults in the Name field.

  4. Select the desired data source.

    graphics/book.gif Choose Recipes from the Connections list.

  5. In the SQL area, enter the following code:

    graphics/vb.gif

    [View full width]

     SELECT * FROM users Inner Join accessgroups ON users.UserAccess = graphics/ccc.gif accessgroups.AccessGroupID WHERE UserFirstName LIKE 'FirstParam%' AND UserLastName LIKE 'LastParam%' AND UserEmail LIKE 'EmailParam%' OR UserAccess = AccessParam 

    graphics/book.gif Paste the copied code in the SQL area by pressing Ctrl-V (Command-V).

Now we'll add four separate variables, one for each of the session variables.

  1. In the Variables section, choose Add (+) and enter the following details in the Add Parameter dialog:

    graphics/553fig01.gif

    The percent sign acts as a wildcard allowing matches with any value if no other value is available. Wildcards are used for all the parameters in this recordset corresponding to the text fields in the search form.

  2. Click OK to close the Add Parameter dialog and then choose Add (+) and enter the following details for the second variable:

    graphics/554fig01.gif

  3. Click OK to close the Add Parameter dialog and then choose Add (+) and enter the following details for the third variable:

    graphics/554fig02.gif

  4. Click OK to close the Add Parameter dialog and then choose Add (+) and enter the following details for the last variable:

    graphics/554fig03.gif

  5. Click OK once to close the Add Parameter dialog and then again to close Recordset dialog.

  6. Be sure to save your page.

Step 3: Data Binding Process

With our recordset built, we're ready to bind the data fields to specific areas of the page. In this page, four data fields are used, representing the email recipient's first name, last name, email address, and access group.

  1. From the Bindings panel, expand the SearchResults recordset.

  2. Place the desired data source fields onto the page:

    graphics/book.gif Drag the UserFirstName field under the Name column.

    Drag the UserLastName field after the UserFirstName field and add a space between the two dynamic text elements.

    Drag the UserEmail field under the Email Address column.

    Drag the AccessGroupName field under the Access Group column.

  3. Save your page [r8-4].


    Figure r8-4.

    graphics/10fig04.jpg


Step 4: Add Links

After the user has checked the search results, there are two possible options: Accept the results or perform the search again. The Mailing List page provides links for both possibilities. If the results are accepted, the user would select the link to the Send Mail page to process the email. If the user decides to run the search again, a link to the Search Users page is available.

The link to the Send Mail page requires a bit of special attention. Because we want the link to be available independent of the current page, we need to pass a parameter that indicates that the recordset culled from the search results should be used. Without the parameter, the Send Mail page will open and allow individual email addresses to be entered by hand.

Let's create the link to the Send Mail page first:

  1. Select the text or image you want to link to the page that actually sends the email.

    graphics/book.gif Select the Send Mail to Group text.

  2. In the Property inspector, select the folder icon next to the Link field to open the Select File dialog.

  3. In the Select File dialog, select Parameters to begin the process of attaching a name/value pair to the URL.

  4. In the Parameters dialog, choose Add (+) and enter the name of the variable you want to pass.

    graphics/book.gif Enter UseRS in the Name column.

  5. Insert the value you want to attach to the link.

    graphics/book.gif Enter 1 in the Value column.

  6. Click OK to close the Parameters dialog.

  7. Select the file you want to link to.

    graphics/vb.gif Select send_mail.asp.

    graphics/js.gif Select send_mail.asp.

    graphics/cf.gif Select send_mail.cfm.

    graphics/php.gif Select send_mail.php.

  8. Click OK to close the Select File dialog.

Now let's create a simple link to the Search Users page. This link effectively replicates the browser's Back button action, but including it indicates the second of the two possible actions the user can choose.

  1. Select the text or image you want to serve as a link to the search page.

    graphics/book.gif Select the Search Again text.

  2. In the Property inspector, select the folder icon to open the Select File dialog.

  3. Choose the search page for your server model.

    graphics/vb.gif Select search_users.asp.

    graphics/js.gif Select search_users.asp.

    graphics/cf.gif Select search_users.cfm.

    graphics/php.gif Select search_users.php.

Step 5: Add Repeat Region

Our final step in the Mailing List recipe is to wrap a Repeat Region server behavior around the embedded data fields.

  1. Select any of the dynamic data fields inserted into the mailing list content area.

  2. From the Tag Selector, choose the table row tag.

    graphics/book.gif Select the <tr> tag from the Tag Selector.

  3. From the Server Behaviors panel, choose Add (+) and select Repeat Region.

  4. In the Repeat Region dialog, choose the desired recordset.

    graphics/book.gif Choose SearchResults from the Recordset list.

  5. Set the Show option to display the number of records you would like.

    graphics/book.gif Choose Show All Records.

  6. Click OK when you're done and save your page.



Macromedia Dreamweaver MX 2004 Web Application Recipes
Macromedia Dreamweaver MX 2004 Web Application Recipes
ISBN: 0735713200
EAN: 2147483647
Year: 2003
Pages: 131

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