?
Solved

Web search engine results on a new page.

Posted on 2003-03-04
7
Medium Priority
?
297 Views
Last Modified: 2013-11-19
hiya, im designing this site and i want to search my database and get back results. i can do this fine.
####################################################
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<%
%>

<%
Dim strURL    

Dim cnnSearch  ' ADO connection
Dim rstSearch  ' ADO recordset
Dim strDBPath  ' path to our Access database (*.mdb) file

Dim strSQL     ' The SQL Query we build on the fly
Dim strSearch  ' The text being looked for

' Retreive the URL of this page from Server Variables
strURL = Request.ServerVariables("URL")

' Retreive the term being searched for.  I'm doing it on
' the QS since that allows people to bookmark results.
' You could just as easily have used the form collection.
strSearch = Request.QueryString("search")
strSearch = Replace(strSearch, "'", "''")

' Since I'm doing this all in one page I need to see if anyone
' has searched for something.  If they have we hit the DB.
' O/W I just show the search form and quit.

%>

<form action="<%= strURL %>" method="get">
<input name="search" value="<%= strSearch %>" />
<input type="submit" />
</form>

<%
If strSearch <> "" Then
     ' MapPath of virtual database file path to a physical path.
     ' If you want you could hard code a physical path here.
     strDBPath = Server.MapPath("dvd.mdb")


     ' Create an ADO Connection to connect to the sample database.
     ' We're using OLE DB but you could just as easily use ODBC or a DSN.
      Set cnnSearch = Server.CreateObject("ADODB.Connection")

     ' This line is for the Access sample database:
     cnnSearch.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"

     ' We're actually using SQL Server so we use this line instead:
     'cnnSearch.Open "Provider=SQLOLEDB;Data Source=10.2.1.214;" _
          '& "Initial Catalog=samples;User Id=samples;Password=password;" _
          '& "Connect Timeout=15;Network Library=dbmssocn;"

     ' Build our query based on the input.
     strSQL = "SELECT DVD_Name, Price, Genre " _
          & "FROM Products " _
          & "WHERE DVD_Name LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
          '& "OR first_name LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
          '& "ORDER BY DVD Name;"

     ' Execute our query using the connection object.  It automatically
     ' creates and returns a recordset which we store in our variable.
     Set rstSearch = cnnSearch.Execute(strSQL)

     ' Display a table of the data in the recordset.  We loop through the
     ' recordset displaying the fields from the table and using MoveNext
     ' to increment to the next record.  We stop when we reach EOF.
     ' For fun I'm combining some fields and showwing you can do more then
     ' just spit out the data in the form it is in in the table.
     %>
     <table border="1">
     <tr>
     <th>Name</th>
     <th>Sales</th>
     </tr>
     <%
     Do While Not rstSearch.EOF
          %>
          <tr>
          <td><%= rstSearch.Fields("DVD_Name").Value %></td></td><td><%= rstSearch.Fields("Price").Value %></td>
          <td><%= rstSearch.Fields("Genre").Value %></td>
          </tr>
          <%

          rstSearch.MoveNext
     Loop
     %>
     </table>
     <%
     ' Close our recordset and connection and dispose of the objects
     rstSearch.Close
     Set rstSearch = Nothing
     cnnSearch.Close
     Set cnnSearch = Nothing
End If


%>

</body>
</html>
####################################################
its just when one runs this code, you get back your results on the same page. i've tried to set up to put it in a new page(FORM, ACTION=XY.asp) but i keep getting it messed up. can anyone show me how to set it up through ASP(VB script), so the results will be on a new page.
thanks.
0
Comment
Question by:mceroche
  • 4
  • 3
7 Comments
 
LVL 8

Expert Comment

by:tncbbthositg
ID: 8067339
since you are using get, it should be fairly easy.  Instead of submitting the form, open a new window.
Put this in the <head> section:


<script type="text/javascript">
function openwindow(searchTerms)
{
window.open("http://xy.asp?search=" + searchTerms,"my_new_window","toolbar=yes,location=yes,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=no,copyhistory=yes,width=400,height=400")
}
</script>


Then, change your submit button to type="button" instead of type="submit".  In that button's tag (<input type="button") write onclick="openwindow(" + document.myform.search.value + ");")

Then, when you click the button, it will call openwindow with the search parameters and open a new window with the search page in it!

Good luck,
Patrick

P.S., I havent debugged the script above but it should get you well on your way.
0
 

Author Comment

by:mceroche
ID: 8067714
hi tncbbthositg,
i did what you said but i seem to be getting an error with
the below;
###################################################
<form action="<%= strURL %>" method="get">
<input name="search" value="<%= strSearch %>" />

<input type="button" onclick="openwindow(" + document.myform.search.value + ");") />  
##################################################
I dont know what the problem is, isnt that what you said to do?
0
 

Author Comment

by:mceroche
ID: 8067743
hi tncbbthositg,
i did what you said but i seem to be getting an error with
the below;
###################################################
<form action="<%= strURL %>" method="get">
<input name="search" value="<%= strSearch %>" />

<input type="button" onclick="openwindow(" + document.myform.search.value + ");") />  
##################################################
I dont know what the problem is, isnt that what you said to do?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 8

Expert Comment

by:tncbbthositg
ID: 8068175
yeah, name your form and change "myform" to whatever you name your form.
0
 

Author Comment

by:mceroche
ID: 8068625
listen Patrick, i'm really sorry about this but it still wont work for me.
i dont know what the problem is, i think i've completed what you said correctly.
this is what my program looks like so far;
*********************************************
<html>
<head><script type="text/javascript">
function openwindow(searchTerms)
{
window.open("http://localhost/MyFypPages/xy.asp?search=" + searchTerms,"my_new_window","toolbar=yes,location=yes,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=no,copyhistory=yes,width=400,height=400")
}
</script>

<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<%
%>

<%
Dim strURL  
Dim cnnSearch  
Dim rstSearch  
Dim strDBPath  
Dim strSQL    
Dim strSearch

strURL = Request.ServerVariables("URL")
strSearch = Request.QueryString("search")
strSearch = Replace(strSearch, "'", "''")
%>

<form name= "input" action="<%= strURL %>" method="get">
<input name="search" value="<%= strSearch %>" />
<input type="button" onclick="open.window(' + document.input.search.value + ');")/>
 
</form>

<%
If strSearch <> "" Then
strDBPath = Server.MapPath("dvd.mdb")
 Set cnnSearch = Server.CreateObject("ADODB.Connection")
cnnSearch.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
strSQL = "SELECT DVD_Name, Price, Genre " _
          & "FROM Products " _
          & "WHERE DVD_Name LIKE '%" & Replace(strSearch, "'", "''") & "%' " _

Set rstSearch = cnnSearch.Execute(strSQL)
%>
     <table border="1">
     <tr>
     <th>Name</th>
     <th>Sales</th>
     </tr>
     <%
     Do While Not rstSearch.EOF
          %>
          <tr>
          <td><%= rstSearch.Fields("DVD_Name").Value %></td></td><td><%= rstSearch.Fields("Price").Value %></td>
          <td><%= rstSearch.Fields("Genre").Value %></td>
          </tr>
          <%

          rstSearch.MoveNext
     Loop
     %>
     </table>
     <%
rstSearch.Close
     Set rstSearch = Nothing
     cnnSearch.Close
     Set cnnSearch = Nothing
End If


%>

</body>
</html>
thanks very much for your help so far.
stephen.

0
 
LVL 8

Accepted Solution

by:
tncbbthositg earned 400 total points
ID: 8068850
Okay stephen, try this:

<html>
<head><script type="text/javascript">
function openwindow(searchTerms)
{
window.open("http://localhost/MyFypPages/xy.asp?search=" + searchTerms,"my_new_window","toolbar=yes,location=yes,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=no,copyhistory=yes,width=400,height=400")
}
</script>

<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<%
%>

<%
Dim strURL  
Dim cnnSearch  
Dim rstSearch  
Dim strDBPath  
Dim strSQL    
Dim strSearch

strURL = Request.ServerVariables("URL")
strSearch = Request.QueryString("search")
strSearch = Replace(strSearch, "'", "''")
%>

<form name= "input" action="" method="get">
<input name="search" value="<%= strSearch %>" />
<input type="button" value="Search" onclick="openwindow(document.input.search.value)"/>

</form>

<%
If strSearch <> "" Then
strDBPath = Server.MapPath("dvd.mdb")
Set cnnSearch = Server.CreateObject("ADODB.Connection")
cnnSearch.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
strSQL = "SELECT DVD_Name, Price, Genre " _
         & "FROM Products " _
         & "WHERE DVD_Name LIKE '%" & Replace(strSearch, "'", "''") & "%' " _

Set rstSearch = cnnSearch.Execute(strSQL)
%>
    <table border="1">
    <tr>
    <th>Name</th>
    <th>Sales</th>
    </tr>
    <%
    Do While Not rstSearch.EOF
         %>
         <tr>
         <td><%= rstSearch.Fields("DVD_Name").Value %></td></td><td><%= rstSearch.Fields("Price").Value %></td>
         <td><%= rstSearch.Fields("Genre").Value %></td>
         </tr>
         <%

         rstSearch.MoveNext
    Loop
    %>
    </table>
    <%
rstSearch.Close
    Set rstSearch = Nothing
    cnnSearch.Close
    Set cnnSearch = Nothing
End If


%>

</body>
</html>
0
 

Author Comment

by:mceroche
ID: 8068982
thanks a lot patrick, you've been very helpful.
steve.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Google webmaster tool or Google search console is an imperative tool for solving different website relevant issues. The amazing features of this tool greatly help to check the indexing and improve the visibility of the site.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses
Course of the Month9 days, 7 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question