Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-24-2006, 03:25 PM   PM User | #1
fondune
New to the CF scene

 
Join Date: Mar 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
fondune is an unknown quantity at this point
Entire recordset appears on page load?!

I have been tasked with creating a search/results page, and really have little to no idea what I am doing. I recieved help from a local tech guy, but have not been able to get a hold of him to solve this problem with the code that he sent me.

Code:
<!-- METADATA TYPE="typelib" 
              FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->
<%
  Dim objConn
  Set objConn = Server.CreateObject("ADODB.Connection")
  objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
               "Data Source= C:\Inetpub\NewHermantown\StaffDirectory\db1.mdb"
%>

<html>
<head></head>
<body>
<form name="form1" method="post" action="directory.asp">
  Enter part or all of the employee's last name:<br>
  <input type="text" name="srch_last">
  <br>
  <input type="submit" name="Submit" value="Search">
</form>
<div align="left">
  <%
  strSQL = "SELECT LastName, FirstName, EmailName FROM Employees " & _
           "WHERE LastName ALIKE """ & Request.Form("srch_last") & "%"" ORDER BY LastName, FirstName, EmailName;"
  
  Set rsItems = Server.CreateObject("ADODB.Recordset")
  rsItems.Open strSQL, objConn
  If Not rsItems.EOF Then
    Do While Not rsItems.EOF
	  Response.Write rsItems("LastName") & ", " & rsItems("FirstName") & ", " & rsItems("EmailName") & ", " & "<br>"
      rsItems.MoveNext
    Loop
    rsItems.close
    Set rsItems = Nothing 
  Else  
    Response.Write "<CENTER><H2>No employees match your search.</H2></CENTER>"
  End If 
%>
</div>
</body>
</html>
When the page loads, the entire recordset is sitting there where the results should be. What line of code am I missing to tell it NOT to display anything when the page loads?

Any help is greatly appreciated!
fondune is offline   Reply With Quote
Old 03-24-2006, 06:15 PM   PM User | #2
Archangel
Registered User

 
Join Date: Jan 2006
Posts: 130
Thanks: 0
Thanked 0 Times in 0 Posts
Archangel is an unknown quantity at this point
Yes, I assume it does because you're not running a check to make sure someone has hit the submit button. Wrap your entire <div> for displaying the results in an if statement.

If Request.Form("srch_last") <> "" Then
<div>
blah blah
End If
Archangel is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:19 PM.


Advertisement
Log in to turn off these ads.