ragol_67
04-11-2005, 08:02 PM
I have a function that works fine, but when I try to add an order command, it doesn't seem to work. Here is the original code:
<!-- #INCLUDE file="DataSource.asp" -->
<%
function ConstructSQL()
dim strDateLow, strDateHigh, strRunLow, strRunHigh
dim strDirector, strTitle
dim strSQL, strWhere
' first get form data
strDateLow = request.form("date_low")
strDateHigh = request.form("date_high")
strBoolean1 = request.form("boolean1")
strRunLow = request.form("run_low")
strRunHigh = request.form("run_high")
strBoolean2 = request.form("boolean2")
strDirector = request.form("director")
strBoolean3 = request.form("boolean3")
strTitle = request.form("title")
' construct first part of SQL statement. We are querying a query
strSQL = "Select * from qryMovies Where "
strWhere = ""
' now add user criteria
if strDateLow <> "" and strDateHigh <> "" then
strWhere = " (ReleaseDate >= #" & strDateLow & "# and ReleaseDate <= #" & strDateHigh & "#) "
end if
if strRunLow <> "" and strRunHigh <> "" then
' only add the And/Or if user entered Release Date criteria
if strWhere <> "" then
strWhere = strWhere & " " & strBoolean1
end if
strWhere = strWhere & " (RunTime >= " & strRunLow & " and RunTime <= " & strRunHigh & ") "
end if
if strDirector <> "" then
if strWhere <> "" then
strWhere = strWhere & " " & strBoolean2
end if
strWhere = strWhere & " (DirectorName Like '" & strDirector & "%')"
end if
if strTitle <> "" then
if strWhere <> "" then
strWhere = strWhere & " " & strBoolean3
end if
strWhere = strWhere & " (Title Like '" & strTitle & "%')"
end if
' check if user did not enter criteria
if strWhere = "" then
strWhere = "true"
end if
ConstructSQL = strSQL & strWhere
End function
%>
<HTML><HEAD><TITLE>Process Search</TITLE></HEAD>
<BODY>
<B>Search Results for:</B><BR><I>
<%
dim strSQL
strSQL = ConstructSQL()
response.write strSQL
%>
</I>
<TABLE BORDER=1>
<TR>
<TD><B>Title</B></TD>
<TD><B>Director</B></TD>
<TD><B>Release Date</B></TD>
<TD><B>Run Time</B></TD>
</TR>
<%
Set objRS = Server.CreateObject("ADODB.recordset")
objRS.open strSQL, strConnect
do while not objRS.eof
response.write "<tr>"
response.write "<td><a href=movie.asp?ID="
response.write objRS("MovieID") & ">"
response.write objRS("Title") & "</a></td>"
response.write "<td>" & objRS("DirectorName") & "</td>"
response.write "<td>" & objRS("ReleaseDate") & "</td>"
response.write "<td>" & objRS("RunTime") & "</td>"
response.write "</tr>"
objRS.MoveNext
Loop
objRS.close
%>
</TABLE>
</BODY></HTML>
It works fine, I can enter search criteria in, and it finds the correct criteria, but when I change all the request.form's, to request.querystring's, the search criteria no longer works. It says that I didn't enter any criteria, therefore it displays all results.
Thank you,
Nick!
<!-- #INCLUDE file="DataSource.asp" -->
<%
function ConstructSQL()
dim strDateLow, strDateHigh, strRunLow, strRunHigh
dim strDirector, strTitle
dim strSQL, strWhere
' first get form data
strDateLow = request.form("date_low")
strDateHigh = request.form("date_high")
strBoolean1 = request.form("boolean1")
strRunLow = request.form("run_low")
strRunHigh = request.form("run_high")
strBoolean2 = request.form("boolean2")
strDirector = request.form("director")
strBoolean3 = request.form("boolean3")
strTitle = request.form("title")
' construct first part of SQL statement. We are querying a query
strSQL = "Select * from qryMovies Where "
strWhere = ""
' now add user criteria
if strDateLow <> "" and strDateHigh <> "" then
strWhere = " (ReleaseDate >= #" & strDateLow & "# and ReleaseDate <= #" & strDateHigh & "#) "
end if
if strRunLow <> "" and strRunHigh <> "" then
' only add the And/Or if user entered Release Date criteria
if strWhere <> "" then
strWhere = strWhere & " " & strBoolean1
end if
strWhere = strWhere & " (RunTime >= " & strRunLow & " and RunTime <= " & strRunHigh & ") "
end if
if strDirector <> "" then
if strWhere <> "" then
strWhere = strWhere & " " & strBoolean2
end if
strWhere = strWhere & " (DirectorName Like '" & strDirector & "%')"
end if
if strTitle <> "" then
if strWhere <> "" then
strWhere = strWhere & " " & strBoolean3
end if
strWhere = strWhere & " (Title Like '" & strTitle & "%')"
end if
' check if user did not enter criteria
if strWhere = "" then
strWhere = "true"
end if
ConstructSQL = strSQL & strWhere
End function
%>
<HTML><HEAD><TITLE>Process Search</TITLE></HEAD>
<BODY>
<B>Search Results for:</B><BR><I>
<%
dim strSQL
strSQL = ConstructSQL()
response.write strSQL
%>
</I>
<TABLE BORDER=1>
<TR>
<TD><B>Title</B></TD>
<TD><B>Director</B></TD>
<TD><B>Release Date</B></TD>
<TD><B>Run Time</B></TD>
</TR>
<%
Set objRS = Server.CreateObject("ADODB.recordset")
objRS.open strSQL, strConnect
do while not objRS.eof
response.write "<tr>"
response.write "<td><a href=movie.asp?ID="
response.write objRS("MovieID") & ">"
response.write objRS("Title") & "</a></td>"
response.write "<td>" & objRS("DirectorName") & "</td>"
response.write "<td>" & objRS("ReleaseDate") & "</td>"
response.write "<td>" & objRS("RunTime") & "</td>"
response.write "</tr>"
objRS.MoveNext
Loop
objRS.close
%>
</TABLE>
</BODY></HTML>
It works fine, I can enter search criteria in, and it finds the correct criteria, but when I change all the request.form's, to request.querystring's, the search criteria no longer works. It says that I didn't enter any criteria, therefore it displays all results.
Thank you,
Nick!