?
Solved

Web search engine results on a new page.

Posted on 2003-03-04
7
Medium Priority
?
294 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

 
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

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

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

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

764 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