[thelist] ASP & SQL

Joshua Olson joshua at waetech.com
Fri Sep 13 13:39:00 CDT 2002


----- Original Message -----
From: "Erik Bennett" <ebennett at ecasd.k12.wi.us>
To: <thelist at lists.evolt.org>
Sent: Friday, September 13, 2002 2:27 PM
Subject: RE: [thelist] ASP & SQL


> Thank you to everyone who wrote back about this. And an extra special
thanks
> to joshua. Your code works beautifully!

You're welcome.
>
> Now just one little thing. :-) I have the search page referencing itself,
> but the problem is that on first call, it gives "WHERE 1=1" as the SQL
> statement, and that returns the entire database. Is there a way to have
the
> table that displays the results be clear on the first pass through
(meaning
> when the page is first called)? Does that make sense? :-)

Sure, don't execute the query and do not run the script that generates the
result set.  Add a conditional before that section that checks to see if you
want to display a result set.  If you want to check that the three variables
are all empty, that's your call.  If you want to pass a hidden value in the
form that says, please perform the lookup, then do that.  Eg:

Add this to your form <input type="hidden" name="action" value="lookup" />

Then, wrap the query and output in this conditional:

If Request.Form("action") = "lookup" Then
  ' Do the query
End If

Then later:

If Request.Form("action") = "lookup" Then
  ' Do the display
End If

The first time through, the value for the hidden field will not be set, and
the two blocks won't execute.  When they submit the search form, the value
will be set, indicating that the calculation should be done.  As a rule of
thumb, never perform a query that you know for sure will not get any
results.  Tis better, at least in a mass web environment, to usually not do
the query.

-joshua




More information about the thelist mailing list