Electric Type

Multimedia

About Us

News

Help

Your First Database
Lesson 4

by Jay Greenspan

Page 3 — Deciphering More of the Code

The next page of our app's interface, info2.asp (seen here), doesn't present anything new. I've just decided to spread out the info-gathering process over two pages. On the following page (infofinal.asp), however, things start to get interesting.

Go ahead and open up this page in a text editor. (Didn't download it? Tsk, tsk! Well, you can look at it here.)

I'm not going to start talking about this page from the top because I think it will make more sense if we start here:


	cost = 100 * grademultiple * transmultiple * carszmultiple

Remember how I wanted to calculate the price of each lesson individually, based on the size of the car, transmission type, and grade type? For that reason, I included a field for a multiple in each of the appropriate database tables. Knowing that's the goal, the preceding database calls should make sense. Let's look at one in detail just to make sure you've got it:



SQLCARRATE="SELECT carName, szMultiple FROM Cars, Size "


SQLCARRATE=SQLCARRATE & "WHERE Cars.szID = Size.szID and carID=" &
carID



set conn = server.createobject("ADODB.Connection")


conn.open "parking"


set carrate=conn.execute(SQLCARRATE)


carname=carrate(0)


carszmultiple=carrate(1)


conn.close


I want you to take note of a couple of things in this code. First, the WHERE portion of our SQL statement achieves an equi-join on the carID field. This allows us to get the name of the car and the rate associated with the car's size in a single database call. I also want to point out that I loaded the retrieved information from the ADO recordset into regular VBScript variables. Technically, this isn't necessary. But I am making three SQL queries with one connection, and I thought these variable names made the code a bit easier to read.

We should also take a moment to look at app.inc, which pulls the available appointments from the database. Here's the code:


<%

SQLAPP="SELECT appID, appTime FROM Appointments WHERE appStatus = 'open' ORDER BY appTime"

set connapp = server.createobject("ADODB.Connection")

connapp.open "parking"

set apps=connapp.execute(SQLAPP)

%>

<font face="arial" size="5">

<% do while not apps.eof



%>



'LOOK AT ME, LOOK AT ME, LOOK AT ME!

<a href="book.asp?carID=<%= carID %>&tranID=<%= tranID %>&gradeID=<%= gradeID



%>&appID=<%= apps(0) %>&appRate=<%= cost %>"><%= apps(1) %></a><br>

<%apps.movenext 

loop%>

</font>



<% connapp.close %>	

</select>

There's one particular line here that's begging for your attention. This link may look awful, but if you take a look at the HTML it creates, I think you'll see the purpose. When rendered, this code simply creates a link with the necessary name=value pairs in the querystring. Here's an example of the text it would create: book.asp?carID=2&tranID=2&gradeID=2&appID=8&appRate=156. Prior to this example, we've only used forms to pass information to the querystring. But this method works just fine.

Once we've managed to pass this information, we're ready to look at our last page.

next page»


Lesson 1  

Lesson 2  

Lesson 3  

Lesson 4  

Authoring Home  

User Blogs

Screen Shots

Latest Updates

Contact Us

Valid HTML 4.01!
Valid CSS!

Breadcrumb

© ElectricType
Maintained by My-Hosts.com
Site map | Copyright | Disclaimer
Privacy policy | Acceptable Use Policy
Legal information.