DreamweaverFAQ.com
Search the site!Search DWfaq.com | Print This PagePrinter Friendly Page
Current: Default | Default: The Roubaix Blues


DreamweaverFAQ.com » Tutorials » Dynamic » Multiple Repeat Regions On The Same Page


Multiple Repeat Regions on the Same Page

Step Three: A Practical Use of Multiple Repeat Regions on the Same Page

You just learned how to use two repeat regions on the same page using a single recordset; however, both regions contained the exact same information and really did not have much practical use. I will now show you an example of how to put this knowledge to good use.

 

Using an If/Then statement to sort your data dynamically

Let's say that you want to display your members based on their Status Level, i.e., whether they have an "Active" status or a "Inactive" status. Use the same page as before, but make sure both repeat regions are set to display "All" records (you may have to change the second repeat region if you followed the 'interlude' on the previous page).

Note: The following example is only one way of performing the sort task; there are many other ways such as modifying the native MM While Loop into a Do While Loop. Again, there are usually many different ways to accomplish the same task.

 

Sorting the first repeat region

The first repeat region will display only those members who have an "Active" status. Remember, in the database there is the column "M_Status" that contains either a "1" (active) or "0" (inactive). You will need to get your hands a little dirty by getting inside the code a bit, but it really isn't going to be too difficult.

Here is the basic vbScript you will be using to dynamically sort your data. I've highlighted the code that will vary in each situation, but the basic premise will be the same each time you use something like this:

<%
If Some RecordSet Data = "Some Value" Then
%>
Do something here
<% End If %>

Go into code view and find the first repeat region:

<% 
While ((Repeat1__numRows <> 0) AND (NOT rsMultiRepeat.EOF)) %>
<p><%=(rsMultiRepeat.Fields.Item("M_FirstName").Value)%></p>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsMultiRepeat.MoveNext()
Wend
rsMultiRepeat.MoveFirst()
%>

And add the following If/Then statement:

<% 
While ((Repeat1__numRows <> 0) AND (NOT rsMultiRepeat.EOF)) %>
<%
If rsMultiRepeat.Fields.Item("M_Status").Value = "1" Then
%>
<p><%=(rsMultiRepeat.Fields.Item("M_FirstName").Value)%></p>
<% End If %>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsMultiRepeat.MoveNext()
Wend
rsMultiRepeat.MoveFirst()
%>

What does the If/Then statement mean? Basically, if the "M_Status" field equals "1", then show its corresponding data in the "M_FirstName" field.

Save the page and preview it in your browser or with the UltraDev Live Data View. You will now see that only those members who have an "Active" status (remember, 1 = active) are displayed on the page in the first repeat region.

 

Sorting the second repeat region

The second repeat region will display only those members who have an "Inactive" status. Remember, in the database there is the column "M_Status" that contains either a "1" (active) or "0" (inactive).

Go into the code view and find the second repeat region:

<% 
While ((Repeat2__numRows <> 0) AND (NOT rsMultiRepeat.EOF)) %>
<p><%=(rsMultiRepeat.Fields.Item("M_FirstName").Value)%></p> <%
Repeat2__index=Repeat2__index+1
Repeat2__numRows=Repeat2__numRows-1
rsMultiRepeat.MoveNext()
Wend
rsMultiRepeat.MoveFirst()
%>

And add the following If/Then statement:

<% 
While ((Repeat2__numRows <> 0) AND (NOT rsMultiRepeat.EOF)) %>
<%
If rsMultiRepeat.Fields.Item("M_Status").Value <> "1" Then
%>

<p><%=(rsMultiRepeat.Fields.Item("M_FirstName").Value)%></p> <% End If %>
<%
Repeat2__index=Repeat2__index+1
Repeat2__numRows=Repeat2__numRows-1
rsMultiRepeat.MoveNext()
Wend
rsMultiRepeat.MoveFirst()
%>

Notice that I used the same If/Then statement as before, however I changed:

.Value = "1" to .Value <> "1"

You probably expected to see me use: .Value = "0". I used the Not Equal sign, "<>" so that the page would display all the records that did not have a corresponding Status value of "1". I could have used .Value = "0", however by using Not Equal to I am guaranteed to see all the records that did not appear in the first repeat region. Why? Because the first repeat region is set to display only the records that equl "1", while the second repeat region is set to display those that do not equal "1".

Save the page and preview it in your browser or with the UltraDev Live Data View. You will now see that your first repeat region shows only those members who have and "Active" status, while the second repeat region shows only those members who DO NOT have an "Active" status and thus are "Inactive" members.

 

Summing It All Up

In this tutorial, you have learned how to:

  1. Use the same recordset more than one time on a page that uses repeat regions by adding a line of code to UltraDev's Repeat Region: rsYourRecordSet.MoveFirst().

  2. Dynamically sort your data using only one recordset and multiple repeat regions using simple If/Then statements.

::This page last modified 8/13/2013 at 03:37::

Copyright © 2001-2019 DreamweaverFAQ.com All Rights Reserved.
All brands, trademarks, tutorials, extensions, code, and articles are the property of their respective owners.
A production of Site Drive Inc.
Legal Notice | Privacy Policy | Disclaimer & Notice