More ASP using Dreamweaver UltraDev
July 9, 2001
|
In "
ASP using Dreamweaver UltraDev and PWS" we looked at
installing Personal Web Server and
Macromedia Dreamweaver UltraDev to create
ASP pages. We also looked at the
recordsets created by UltraDev and the VBScript lines that write
data into the page. Now we'll consider
URL strings, links to
detail pages and displaying the returned data, using a real world
example of a page created for a hospital to produce instant
reports from patient admission data.
|
Linking to Detail Pages
Creating links so your visitor can click on an item of data and
to go to a more detailed Web page is easy using UltraDev. The
link is created in the Server Behaviours window and the code
looks something like this:
<A HREF="appt_level2.asp?<%= MM_keepURL &
MM_joinChar(MM_keepURL) amp; "DoH=" &
APPT.Fields.Item("DoH").Value %>">
After this code comes the data to be linked, which is likely to
be a dynamic element, and then the closing
</a> tag.
The first part of the code shown above is HTML defining the page
your visitor will go to — appt_level2.asp. There's a
question mark after the page address, and the URL string
parameters will follow this. Putting parameters in the URL string
is the easy way of transferring them from page to page.
The next elements are references to Macromedia subroutines
(beginning MM) that create the new URL string. In this case we
use the subroutine that collects existing parameters in the
current URL string and passes them on to the next page, then a
join character, and finally a new addition to the string,
beginning with "DoH=". This will add a DoH code to
the URL string, In our hospital example, DoH is a numeric value
corresponding to a medical specialty. For example 190 is
Anesthetics.
The code snippet APPT.Fields.Item("DoH").Value
retrieves the appropriate value to be added to the URL string. It
looks along the row of data for the DoH code and inserts it in
the URL string. If we were starting off with a page that had a
blank URL string, we might finish up moving to a detail page
containing the string: appt_level2.asp?DoH=190.
Extracting values from strings
On the detail page appt_level2.asp, we need to extract the
DoH value from the string to use it as a filtering parameter
within a recordset — specifically within an
SQL
Select statement. Again UltraDev makes this straightforward,
allowing us to specify a URL parameter for filtering during
creation of the recordset.
It transfers the useful part of the URL string to a VBScript
variable first. So if we are creating a recordset called
rswebtotals and we use our previously mentioned DoH as a
limiting element of the recordset's SQL statement, we find the
following code created by UltrDev near the start of the page:
<%
Dim rswebtotals__varDOH
rswebtotals__varDOH = 100
if(Request.QueryString("DoH") <> "")
then rswebtotals__varDOH = Request.QueryString("DoH")
%>
[Lines 4 and 5 above are one line. They have been split for
formatting purposes.]
This creates a variable called rswebtotals__varDOH
and sets it equal to the value of DoH that it finds in the URL
string. In case the string is empty, it first sets it to a user-
specified value of 100. This is helpful when testing the page
since it prevents missing parameter errors that might otherwise
occur.
The variable rswebtotals__varDOH can also be
displayed anywhere it's required on the page using the simple
code <%= rswebtotals__varDOH %>.
The SQL Select Statement - Page 2
|