Forum Moderators: open

Message Too Old, No Replies

results?

         

stevelibby

4:32 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



Finally i have got info to goto the db and show a search result. Clap , Clap
Right,
1)How can i get it to not put any information in to my db until a search has been done?
2) How do i capture the ipaddress of the searcher?

<%
variable1 = Request.form("Search")
%>

<!--#include file="connection.inc"-->
<%
DIM mySQL, objRS
mySQL = "INSERT INTO SiteSearch (Search) VALUES ('" & variable1 & "');"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open mySQL, objConn
%>
<form method="POST" action="searchtest2.asp">
<p>
<input type="text" name="Search" size="20">
<input type="submit" value="Submit" name="">
</p>
</form>

Your search for <%=Request("Search")%>

txbakers

4:43 pm on Feb 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to do some research into the syntax for the "INSERT INTO......SELECT" SQL command.

That is what you are looking for.

Without all your details, there is no sense writing out some code for you to cut and paste into your file.

You have all the tools you need, you just need to learn the syntax for doing what you want to do.

Research that syntax and your problem will be solved.

stevelibby

4:57 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



But i dont fully understand it all, how would i construct a statement that would wait until a search has been completed as my main issue is a refresh is deemed as a search..

Easy_Coder

6:14 pm on Feb 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I agree with txbakers, if you're not sure about the flow of events then you're getting ahead of yourself and that's not the time to consider database interactivity or you'll wind up producing code that will cause problems. Gotta know how it works right?

So how do you determine 'Flow of events'? Well just walk it through on a white board or piece of paper. I've even done em on restaurant napkins during lunch.

Here's an idea to get you going:


--> User arrives on search page.
--> Is Search Submitted?
--> Yes
--> Isolate IP Address (Research Request.ServerVariables to accomplish this step)
--> Isolate Search Phrase (Research Request.Form to accomplish this step)
--> Record Search Phrase (Looks like you have that but logistically it's in the wrong place)
--> Perform Search Algorithm
--> Do Results exist?
--> No
--> Gracefully inform the user.
--> Yes
--> Unwind result set.
--> No
--> Do nothing.

Now, once you've done this. Think up some ways to break it (illegal characters for example). This is testing and it's really important if your application is going to interact with a database. Testing might reveal bugs in your algorithm that you'll want to correct before writing any code.

After you feel that you've got the bugs all ironed out then write your code. You'll be much better off in the long run by hammering out all of your bugs while your in design. That way when you sit down to write your code it's going to go very fast and with very little re-writes.

stevelibby

6:51 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



Thank you for that:
I have now got this far:
<%
variable1 = Request.form("Search")
variable2 = Request.ServerVariables("remote_addr")
%>

<!--#include file="connectstring.inc"-->
<%
DIM mySQL, objRS
mySQL = "INSERT INTO SiteSearch (Search, Time, Date, IPaddress) VALUES ('" & variable1 & "','" & Time() & "','" & Date() & "','" & variable2 & "');"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open mySQL, objConn
%>

I am self taught, so appologise in advance. This now works and sends info to db and passes the string accross to the results part.....pat myself on the back Clap, clap.
The results part just for the moment is made up of a simple frontpage wizard which will be changing shortly.

The bit that i am not sure on is:
--> Isolate IP Address (Research Request.ServerVariables to accomplish this step) --> Isolate Search Phrase (Research Request.Form to accomplish this step)

Also how do i go about counting results?

Im not doing bad for a beginer though!

Easy_Coder

7:04 pm on Feb 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The bit that i am not sure on is: (Research Request.Form to accomplish this step)

--> Isolate IP Address (Research Request.ServerVariables to accomplish this step)
sUsersIPAddress = Request.ServerVariables("REMOTE_ADDR")

Also how do i go about counting results?

Where's your code that is actually performing the search? So far I'm only seeing the piece that persists the search string and from the looks of things it fires unconditionally. Ideally, that would be conditional, right?

Like so:
variable1 = Request.form("Search")

If Trim(variable1) <> "" Then

Rem - ok to save the phrase
mySQL = "INSERT INTO SiteSearch (Search) VALUES ('" & variable1 & "');"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open mySQL, objConn

End If

stevelibby

7:30 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



the search bit at the moment is done by frontpage and in short i believe its:
SELECT * FROM Tags WHERE (Category LIKE '%::Search::%' OR Title LIKE '%::Search::%' OR Description LIKE '%::Search::%') ORDER BY Category ASC,Title ASC
all it is doing is searching a table that i have created for my meta tags. As i say, i will to the relevance of it all a bit later.
I know its a a little naf, but i havent got that far yet.
tell me about the "Trim" how does that work?

Easy_Coder

7:41 pm on Feb 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Go here and do some research: [w3schools.com...]

You'll find Trim() under String Functions. Bone up on asp a bit then get started.

stevelibby

7:54 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



I have got an idea but until i build something i am finding it hard to put together.
what should i do next, i have created a form which passes data to my db and then passes it to a search page, so far i am happy with that.
Where do i go next? How should i go about creating the formula for my search?

Easy_Coder

8:02 pm on Feb 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Go to that same site and readup on the ADO tutorials specifically the ADO Recorsdset, Connection and Command Objects.