Click to See Complete Forum and Search --> : Asp Stop Code


petrod
04-06-2004, 01:15 PM
In a code that looks like this and works
If Request.Form("TypeSearch") = "name" Then
strSQL = strSQL & " WHERE nome_htl LIKE '%" & _
Request.Form("DaInBox") & "%'"
End If
how i could integrate this code
If (DaInBox="") Then
%>
<H2> Sorry, no result were found!</H2>
<%
Response.End
End if

Stopper31
04-06-2004, 02:58 PM
How about:

<%If Request.Form("TypeSearch") = "name" AND Request.Form("DaInBox") <> "" Then
strSQL = strSQL & " WHERE nome_htl LIKE '%" & _
Request.Form("DaInBox") & "%'"
Else%>
<H2> Sorry, no result were found!</H2>
<%Response.End
End If%>

Please correct me if this isn't the result you're looking for!

buntine
04-06-2004, 07:39 PM
You will need to use an elseif statement. As an else will only execute if TypeSEarch doesnt equal 'name'.

If Request.Form("TypeSearch") = "name" Then
strSQL = strSQL & " WHERE nome_htl LIKE '%" & _
Request.Form("DaInBox") & "%'"
elseIf DaInBox = "" Then
Response.Write ("<H2> Sorry, no result were found!</H2>")
Response.End
End if

Regards,
Andrew Buntine.

Stopper31
04-06-2004, 11:41 PM
I just assumed that since the variable he's checking was from the Request.Form and not his search results... that it would be incorporated in the original If statement... but like I said, I can't quite tell what he's actually looking to achieve... whether or not the Search returns anything... or if the user has left said Request.Form variable empty cause if it is, there's not much appending it to the WHERE clause!

petrod
04-07-2004, 12:53 AM
I want if the search button is pressed and the DaInBox is empty not to have any results.If i leave it as my original code and u press search with nothing typed in it will give all the results.I tried the answers already posted but i cant seem to make them work.I will try it more.
But thanks for answering.

buntine
04-07-2004, 01:32 AM
Stopper: I see what you mean;) But the statement sequence following an else statement will only be executed if the original conditional clause resulted in false. So in this case, it wont do the job.

petrod: Could you post the code your currently using? Provided its different from the original code you posted, of coarse.

Regards,
Andrew Buntine.

CardboardHammer
04-07-2004, 10:01 AM
Heck, the code will work (EDIT: almost) exactly as written in the original post: back to back blocks. Though it would be more efficient to put the second block first, as there's no point building the query string if the query won't be made.

EDIT: Wait a second... If (DaInBox="") Then in the second block should be If (Request.Form("DaInBox") ="") Then instead.

Stopper31
04-07-2004, 01:58 PM
Originally posted by petrod
I want if the search button is pressed and the DaInBox is empty not to have any results.If i leave it as my original code and u press search with nothing typed in it will give all the results.I tried the answers already posted but i cant seem to make them work.I will try it more.
But thanks for answering.
From what you're saying, I'd think my example above would be what you're looking for... in pseudo, what my example is doing is checking:

If the user is searching AND has filled out "DaInBox", then append "DaInBox" to WHERE clause ELSE throw up a "No results found" even though you're not actually performing a search!

Sounds like it would work the way you want... but let us know if that didnt' work!

Stopper31
04-07-2004, 02:00 PM
Originally posted by buntine
Stopper: I see what you mean;) But the statement sequence following an else statement will only be executed if the original conditional clause resulted in false. So in this case, it wont do the job.
From what I gather, that's what he's looking for... if the search is performed, and the "DaInBox" is not empty, append it, else throw up a "No results Found" simply based on them not filling in "DaInBox"... ??!?!?!

buntine
04-07-2004, 02:06 PM
Not sure...
However, your else statement will still result true if 'typeSearch' doesnt equal "name". And he only wants that peice to execute if 'daInBox' is null.

Regards.

Stopper31
04-07-2004, 02:15 PM
Ahhhh, that's true... good catch!! I guess what he'll need is a nested IF like this:


<%If Request.Form("TypeSearch") = "name" Then
If Request.Form("DaInBox") <> "" Then
strSQL = strSQL & " WHERE nome_htl LIKE '%" & _
Request.Form("DaInBox") & "%'"
Else%>
<H2> Sorry, no result were found!</H2>
<%Response.End
End If
End If

buntine
04-07-2004, 02:22 PM
The code i originally gave him will work.. As it employs an elseif statement (which is the equivelant of a nested if, but more efficient :D).

Regards.

Stopper31
04-07-2004, 02:27 PM
Originally posted by buntine
The code i originally gave him will work.. As it employs an elseif statement (which is the equivelant of a nested if, but more efficient :D).
I agree that an ElseIf is more efficient, but in this case, I thought that the only time to check "DaInBox" was if TypeSearch = "name", therefore, if the first part equates to True, then it'll never check "DaInBox" in your example... man, this is turning into quite the code-tossing event!! I'm not trying to keep disagreeing with you Buntine, I just think we're reading his request differently.

buntine
04-07-2004, 02:29 PM
Dont worry, I wont get angry. ;)

He hasnt given us enough details... Im not sure whether he wants the if statement nested, tree-ed or seperate.

Regards.

Stopper31
04-07-2004, 02:31 PM
:D lol... petrod, please shed us some light here... we're dying!!!

petrod
04-07-2004, 11:28 PM
The code i tried is this:
If Request.Form("TypeSearch") = "name" Then
strSQL = strSQL & " WHERE nome_htl LIKE '%" & Request.Form("DaInBox") & "%'"
elseIf DaInBox = "" Then
Response.Write ("<H2> Sorry, no result were found! </H2>")
End if

If Request.Form("TypeSearch") = "town" Then
strSQL = strSQL & " WHERE town_htl LIKE '%" & Request.Form("DaInBox") & "%'"
elseIf DaInBox = "" Then
Response.Write ("<H2> Sorry, no result were found! </H2>")
End if
Set objRS = Server.CreateObject("ADODB.Recordset")

objRS.Open strSQL, objConn
%>

<%
If objRS.BOF and objRS.EOF Then%>

<h2 align="center">Sorry, no result were found! Please try again</h2>
<%Else%>
i can see the reuslts.

There is a drop down menu that u can make choises "TypeSearch" and there is a search entry for the user DaInBox.
With the original code i can see records, i can see that if there is soemthing not there, the message not found, but i cant make it show me the message, no result, if the users chooses somthing from the dropr down menu but types nothing on the box "DaInBox" and press the search button.
With your solution i can get no reults found if i dont put anything but i get the same answer if i put a string that must return results

Stopper31
04-07-2004, 11:45 PM
I think by using my nested If example, you should get the results you want... you can nest it in a very large if to take in to account all your search types:


<%
If Request.Form("DaInBox") = "" Then
Response.Write ("<H2> Sorry, no result were found!</H2>")
Else
If Request.Form("TypeSearch") = "name" Then
strSQL = strSQL & " WHERE nome_htl LIKE '%" &
Request.Form("DaInBox") & "%'"
ElseIf Request.Form("TypeSearch") = "town" Then
strSQL = strSQL & " WHERE town_htl LIKE '%" &
Request.Form("DaInBox") & "%'"
End If

Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strSQL, objConn

If objRS.BOF and objRS.EOF Then
Response.Write ("<H2> Sorry, no result were found!</H2>")
Else
'Print results
End If
End If


I've assumed that Request.Form("TypeSearch") will contain something from the previous dropdown.

petrod
04-08-2004, 12:24 AM
the code that u gave me
If Request.Form("DaInBox") = "" Then
Response.Write ("<H2> Sorry, no result were found!</H2>")
elseIf Request.Form("TypeSearch") = "code" then
strSQL = strSQL & " WHERE cod_htl LIKE '%" & Request.Form("DaInBox") & "%'"
elseIf Request.Form("TypeSearch") = "name" Then
strSQL = strSQL & " WHERE nome_htl LIKE '%" & Request.Form("DaInBox") & "%'"
End If
Its not working.When i press nothing it gives the message no reult was found but then coninues and gives me the results.When i ask for a true reulst it will show it.

Sorry my friend i dont know what to say.

This the code for the search button
<td align="left" width="200"><select name="TypeSearch" size="1">
<option selected value="code">Sport Code</option>
<option value="name">sport Name </option>
</select></td>
<td width="310" align="right"><input type="text" size="30" name="DaInBox"></td>
</tr>
<tr>
<td colspan="2" width="197"><div align="left"><p><input type="submit"
name="B1" value="Search For sport!"><input type="reset" name="B2" value="Clear">
</td>

Stopper31
04-08-2004, 12:31 AM
You didn't use the code quite how I used it... as you can see in my example, I've only done the SQL search (opening the recordset) within the nested IF... I can't tell where you are doing it, but I assume it's after this code you've shown me.

You've changed the first nested if to an elseif instead of nesting it like I've shown on a seperate line...

petrod
04-08-2004, 12:36 AM
This is the code i use from that line and beyond.

Set objRS = Server.CreateObject("ADODB.Recordset")

objRS.Open strSQL, objConn
%>

<%
If objRS.BOF and objRS.EOF Then%>

<h2 align="center">Sorry, no result were found! Please try again</h2>
<%Else%>

<%If Not objRS.BOF Then%>

<h2>Here are the results of your search:</h2>

<table BORDER="5" width="100%" cellpadding="4">
<tr>
<th bgcolor="#800000"><font face="Arial" color="#FFFFFF">Code </font></th>
<th bgcolor="#800000"><font face="Arial" color="#FFFFFF">Name </font></th>
</tr>
<%
Do While Not objRS.EOF
%>
<tr>
<td><%=objRS("cod_htl")%>
</td>
<td><%=objRS("nome_htl")%>
</td>
</tr>
<% objRS.MoveNext
Loop
%>
</table>
<%End If%>
<%End If%>
<%
objRS.Close
objConn.Close
%>
<P><A Href="searchpage.asp">Go Back</A></P>
</body>
</html>

Stopper31
04-08-2004, 12:40 AM
Exactly... so you're still opening your recordset even after you check... notice how I've nested the opening of the recordset within my Else clause... if you'd prefer, you can e-mail your entire page to adamsherry@shaw.ca and I'll modify it for you so you can see exactly what I mean.

petrod
04-08-2004, 12:54 AM
Thanks very much man.
I solved it........
;) :) ;) :D :D


I was so stupid i wasnt getting the value of the Dainbox!!!

Stopper31
04-08-2004, 12:56 AM
Alright... hope I helped!