PDA

View Full Version : Expanding Search - PLEASE HELP!!


startbar
02-19-2005, 12:09 PM
Hi, i currently have a search facility to search from an MS Access database (the code is below)

Basically its a form for if someone was searching for a Plumber in Liskeard they would type 'Plumber Liskeard' but that returns no results because 'Plumber' is the keyword and 'Liskeard' is the town.

At the moment is searches like browse.asp?display=KEYWORD

What i need to be able to do is search by more than one thing at once for example a Keyword and a Town or a Category and a Town.

I tried browse.asp?display=KEYWORD&Contacttown=TOWN but it doesnt work!

Please Help, Thanks



<%
Const adOpenStatic = 3
Const adLockReadOnly = 1
Const adCmdText = &H0001

Const PAGE_SIZE = 10 ' The size of our pages.

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

Dim iPageCurrent ' The page we're currently on
Dim iPageCount ' Number of pages of records
Dim iRecordCount ' Count of the records returned
Dim I ' Standard looping variable

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("display")
strSearch = Replace(strSearch, "'", "''")

' Retrieve page to show or default to the first
If Request.QueryString("page") = "" Then
iPageCurrent = 1
Else
iPageCurrent = CInt(Request.QueryString("page"))
End If
%>


<html>
<head>

<link rel="stylesheet" href="/network/css.css" type="text/css">


</head>

<body topmargin="0" leftmargin="0" bgcolor="#767676">

<!--#include virtual="/network/header.html"-->


<table valign="top" border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
<tr>
<td width="790" style="background-color: #767676; padding: 0px; margin: 0px auto; border: 0px solid #4b4b4b">

<%
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("PATH TO DATABASE")


' 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 & ";"


' Build our query based on the input.

dim ordervariable, sortorder
ordervariable = "NameCompany" 'default column to sort on
sortorder = "ASC" 'default sortorder

if (len(request.querystring("sortby")) >= 1) then
ordervariable = request.querystring("sortby")
end if
if (len(request.querystring("sortorder")) >= 1) then
sortorder = request.querystring("sortorder")
end if

strSearch = Replace(strSearch, "'", "''")
strSQL = "SELECT NameCompany, Category, ContactTown, ContactCounty, DescriptionSmall, Keywords, ID, Status " _
& "FROM NETWORK " _
& "WHERE Status=1 " _
& "AND (NameCompany LIKE '%" & strSearch & "%' " _
& "OR Category LIKE '%" & strSearch & "%' " _
& "OR ContactTown LIKE '%" & strSearch & "%' " _
& "OR Keywords LIKE '%" & strSearch & "%') " _
& "ORDER BY " & ordervariable & " " & sortorder

Set rstSearch = Server.CreateObject("ADODB.Recordset")
rstSearch.PageSize = PAGE_SIZE
rstSearch.CacheSize = PAGE_SIZE

rstSearch.Open strSQL, cnnSearch, adOpenStatic, adLockReadOnly, adCmdText

iRecordCount = rstSearch.RecordCount
iPageCount = rstSearch.PageCount

If iRecordCount = 0 Then
' Display no records error.
%>


<title>Startbar.co.uk :: No Results Found</title>


<table cellpadding="5" cellspacing="0" width="100%" height="3" bgcolor="#767676" align="center">
<tr><td width="100%" valign="top" align="left" style="background-color: #4b4b4b; margin: 0px auto;"></td></tr></table>

<table cellpadding="0" cellspacing="0" width="100%" height="2" bgcolor="#cccccc" align="center">
<tr>

<td width="100%" valign="top" align="left" style="background-color: #4b4b4b; margin: 0px auto; border: 0px solid #767676;">

<table cellpadding="0" cellspacing="0" width="99%" height="2" bgcolor="#cccccc" align="center">

<tr>

<td width="100%" height="100%" valign="top" align="left" style="background-color: #5B5A5A; padding: 4px; margin: 0px auto; border: 1px solid #767676;">
<div style="padding-top:5px;padding-bottom:5px;padding-left:5px;padding-right:5px;">
<img src="/network/images/nores.gif"><BR><BR>
<%
if strSearch = "%" then
response.write "No Entries in Database"
else
response.write "but your search for '<b>" & strSearch & "</b>' has returned no results from our database. <BR><BR><b>Search Tips:</b><br>Our search facility uses keywords, categories, company names and towns to return results from the database. Please ensure that all search keywords are spelled correctly and spaced where appropriate. Note that use of symbols can also affect search results!<BR><BR>Please <a href=""/network/search.asp"" class=""tryagain"">click here</a> to go to the advanced search options page"
end if
%>

</div>
</td></tr></table>


</td>

</tr>
</table>

<table cellpadding="5" cellspacing="0" width="100%" height="3" bgcolor="#767676" align="center">
<tr><td width="100%" valign="top" align="left" style="background-color: #4b4b4b; margin: 0px auto;"></td></tr></table>


<%
Else
' Move to the page we need to show.
rstSearch.AbsolutePage = iPageCurrent

' Show a quick status line letting people know where they are:
%>

<%
' 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 cellpadding="5" cellspacing="0" width="100%" height="3" bgcolor="#767676" align="center">
<tr><td width="100%" valign="top" align="left" style="background-color: #4b4b4b; margin: 0px auto;"></td></tr></table>


<table cellpadding="0" cellspacing="0" width="100%" height="2" bgcolor="#cccccc" align="center">
<tr>

<td width="100%" valign="top" align="left" style="background-color: #4b4b4b; margin: 0px auto; border: 0px solid #767676;">

<table cellpadding="0" cellspacing="0" width="99%" height="2" bgcolor="#cccccc" align="center">

<tr>

<td width="100%" height="100%" valign="top" align="left" style="background-color: #5B5A5A; padding: 4px; margin: 0px auto; border: 1px solid #767676;">
<div style="padding-top:5px;padding-bottom:5px;padding-left:5px;padding-right:5px;">

<%
if strSearch = "%" then
response.write "<img src=""/network/images/browseheader.gif"">"
else
response.write "<img src=""/network/images/yoursearch.gif"">"
end if
%>
<BR>
<%
if strSearch = "%" then
response.write "You are currently browsing all company entries totalling " & iRecordCount & "."
else
response.write "<BR>Your search for '<b>" & strSearch & "</b>' returned " & iRecordCount & " result(s)."
end if
%>

</div>
</td></tr></table>


</td>

</tr>
</table>

<table cellpadding="5" cellspacing="0" width="100%" height="3" bgcolor="#767676" align="center">
<tr><td width="100%" valign="top" align="left" style="background-color: #4b4b4b; margin: 0px auto;"></td></tr></table>

<table cellpadding="0" cellspacing="0" width="100%" height="2" bgcolor="#cccccc" align="center">
<tr>
<td width="100%" valign="top" align="left" style="background-color: #4b4b4b; margin: 0px auto; border: 0px solid #767676;">

<table cellpadding="0" cellspacing="0" width="99%" height="2" bgcolor="#cccccc" align="center">

<tr>

<td width="10%" height="100%" valign="top" align="left" style="background-color: #4b4b4b; padding: 4px; margin: 0px auto; border: 0px solid #767676;">
<div style="padding-top:3px;padding-bottom:3px;padding-left:6px;padding-right:6px;"><B>Sort By:</B></div></td>

<td width="74%" height="100%" valign="top" align="left" style="background-color: #4b4b4b; padding: 4px; margin: 0px auto; border: 0px solid #767676;">
<div style="padding-top:3px;padding-bottom:3px;padding-left:6px;padding-right:6px;"><%
if strSearch = "%" then
response.write "<a href=""browse.asp?display=" & strSearch & "25&page=" & iPageCurrent & "&sortby=NameCompany&sortorder=ASC"" class=""menu"">Company Name</a> / <a href=""browse.asp?display=" & strSearch & "25&page=" & iPageCurrent & "&sortby=Category&sortorder=ASC"" class=""menu"">Category</a>"
else
response.write "<a href=""browse.asp?display=" & strSearch & "&page=" & iPageCurrent & "&sortby=NameCompany&sortorder=ASC"" class=""menu"">Company Name</a> / <a href=""browse.asp?display=" & strSearch & "&page=" & iPageCurrent & "&sortby=Category&sortorder=ASC"" class=""menu"">Category</a>"
end if
%></div></td>

<td width="16%" height="100%" valign="top" align="left" valign="center" style="background-color: #4b4b4b; padding: 4px; margin: 0px auto; border: 0px solid #767676;"><div style="padding-top:3px;padding-bottom:3px;padding-left:6px;padding-right:6px;"><%
if strSearch = "%" then
response.write "<a href=""browse.asp?display=" & strSearch & "25&page=" & iPageCurrent & "&sortby=ContactTown&sortorder=ASC"" class=""menu"">Location</a>"
else
response.write "<a href=""browse.asp?display=" & strSearch & "&page=" & iPageCurrent & "&sortby=ContactTown&sortorder=ASC"" class=""menu"">Location</a>"
end if
%></div></td>

</tr></table>


</td>

</tr>
</table>



<table cellpadding="5" cellspacing="0" width="100%" height="3" bgcolor="#767676" align="center">
<tr><td width="100%" valign="top" align="left" style="background-color: #4b4b4b; margin: 0px auto;"></td></tr></table>




<%
Do While Not rstSearch.EOF And rstSearch.AbsolutePage = iPageCurrent
%>

<table cellpadding="0" cellspacing="0" width="100%" height="2" bgcolor="#cccccc" align="center">
<tr>

<td width="100%" valign="top" align="left" style="background-color: #4b4b4b; margin: 0px auto; border: 0px solid #767676;">

<table cellpadding="0" cellspacing="0" width="99%" height="2" bgcolor="#cccccc" align="center">

<tr>

<td width="10%" height="100%" valign="top" align="left" valign="center" style="background-color: #5B5A5A; padding: 0px; margin: 0px auto; border-top: 1px solid #767676; border-bottom: 1px solid #767676; border-left: 1px solid #767676; border-right: 1px solid #767676;"><%
dim fileName
fileName = rstSearch.Fields("NameCompany")
if fileName = "" or IsNull(fileName) then
response.write "<img src=""/network/images/small/no.gif"">"
else
response.write "<img src=""/network/images/small/" & fileName & ".gif"">"
end if
%></td>

<td width="74%" height="100%" valign="top" align="left" style="background-color: #5B5A5A; padding: 4px; margin: 0px auto; border-top: 1px solid #767676; border-bottom: 1px solid #767676; border-right: 0px solid #767676;">
<div style="padding-top:5px;padding-bottom:5px;padding-left:6px;padding-right:6px;">

<img src="/network/images/companyarrow.gif"> <a class="menu1" href="company.asp?view=viewcompany&ID=<%= rstSearch.Fields("ID").Value %>"><%= rstSearch.Fields("NameCompany").Value %></a> ( <a class="browse-category" href="/network/catselect.asp?category=<%= rstSearch.Fields("Category").Value %>"><%= rstSearch.Fields("Category").Value %></a> )<BR>
<%= rstSearch.Fields("DescriptionSmall").Value %><BR>


</div>
</td>


<td width="16%" height="100%" valign="center" align="left" valign="center" style="background-color: #5B5A5A; padding: 0px; margin: 0px auto; border-top: 1px solid #767676; border-bottom: 1px solid #767676; border-left: 1px solid #767676; border-right: 1px solid #767676;">
<div style="padding-top:5px;padding-bottom:5px;padding-left:6px;padding-right:6px;">
<a class="browse-category" href="/network/browse.asp?display=<%= rstSearch.Fields("ContactTown").Value %>"><%= rstSearch.Fields("ContactTown").Value %></a></div></td>



</tr></table>


</td>

</tr>
</table>



<table cellpadding="5" cellspacing="0" width="100%" height="3" bgcolor="#767676" align="center">
<tr><td width="100%" valign="top" align="left" style="background-color: #4b4b4b; margin: 0px auto;"></td></tr></table>

<%

rstSearch.MoveNext
Loop
%>





<table cellpadding="0" cellspacing="0" width="100%" height="2" bgcolor="#cccccc" align="center">
<tr>

<td width="100%" valign="top" align="left" style="background-color: #4b4b4b; margin: 0px auto; border: 0px solid #767676;">

<table cellpadding="0" cellspacing="0" width="99%" height="2" bgcolor="#cccccc" align="center">

<tr>

<td height="100%" valign="top" align="left" style="background-color: #4b4b4b; padding: 4px; margin: 0px auto; border-bottom: 1px solid #5B5A5A;">
<div style="padding-top:1px;padding-bottom:1px;padding-left:1px;padding-right:1px;">



Displaying Page <font class="cpage"><%=iPageCurrent%> of <%=iPageCount%> </font>
</font>

</div>
</td>

<td height="100%" valign="top" align="right" style="background-color: #4b4b4b; padding: 4px; margin: 0px auto; border-bottom: 1px solid #5B5A5A;">

<div style="padding-top:1px;padding-bottom:1px;padding-left:1px;padding-right:1px;">
<%
' Now we need to show our navigation links:

' Show "previous" and "next" page links which pass the page to
' view our search parameter. You could also use form buttons
' but I find this looks better.
If iPageCurrent > 1 Then
%>


<img src="/network/images/previouspage.gif" border="0"> <a href="<%= strURL %>?display=<%= Server.URLEncode(strSearch) %>&page=<%= iPageCurrent - 1 %>&sortby=<%=ordervariable%>&sortorder=<%=sortorder%>" class="menu">Previous Page</a>
<%
End If

' You can also show page numbers:
For I = 1 To iPageCount
If I = iPageCurrent Then
%>
<img src="/network/images/pagedivider.gif" border="0">
<%
Else
%>

<%
End If
Next 'I

If iPageCurrent < iPageCount Then
%></font>
<a href="<%= strURL %>?display=<%= Server.URLEncode(strSearch) %>&page=<%= iPageCurrent + 1 %>&sortby=<%=ordervariable%>&sortorder=<%=sortorder%>" class="menu"> Next Page</a> <img src="/network/images/nextpage.gif" border="0">

</div>
</td>

</tr></table>

</td>

</tr>
</table>

<% End If %>

<%
End If

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


<table cellpadding="5" cellspacing="0" width="100%" height="3" bgcolor="#767676" align="center">
<tr><td width="100%" valign="top" align="left" style="background-color: #4b4b4b; margin: 0px auto;"></td></tr></table>



</td>


<table cellpadding="0" cellspacing="0" width="780" height="2" bgcolor="#4b4b4b" align="center">

<tr>

<td width="100%" valign="top" align="left" style="background-color: #4b4b4b; padding: 4px; margin: 0px auto;">

<!--#include virtual="/network/footer.html"-->

</td>

</tr>
</table>


</div>


</body>
</html>

startbar
02-19-2005, 04:24 PM
i dont know if i explained very well but basically i want users to be able to search by a keyword and then a town - i.e Plumbers in Liskeard.

Please help, very urgent that i get this sorted!!

thanks for your time.

miranda
02-20-2005, 04:09 AM
The big search engines use an index to handle this type of search. Do you have certain categories like plumber, etc.. that will be searched in? if so why not just use a dropdownlist for that part of the search for the user to select and then they can type in the keyword to search for.

If that isn't possible what about listing the keywords in an index or in a separate field in the database. Then put your searchwords into an array and loop through the array do the search.

startbar
02-20-2005, 12:03 PM
hi, thanks for your help.

Yes i have categories like plumber etc but i didnt really understand what you told me! Sorry, im fairly new to asp and this search problem is driving me crazy.

Can you give me some examples and help me out a bit more?

THANK YOU, i really appriciate it.

miranda
02-20-2005, 07:07 PM
here is a simple example for you

<%@ Language=VBScript %>
<%Option Explicit
Dim sCategory, sCriteria
sCategory = Request.Form("category")
sCriteria = Request.Form("criteria")
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<form method="post" action="<%=Request.ServerVariables("URL")%>">
Search category: <select name="category">
<option value="plumber"<%=If sCategory = "plumber" Then Response.Write " Selected"%>>Plumber</option>
<option value="carpenter"<%=If sCategory = "carpenter" Then Response.Write " Selected"%>>Carpenter</option>
<option value="electrician"<%=If sCategory = "electrician" Then Response.Write " Selected"%>>Electrician</option>
</select><br />
Search Criteria: <INPUT type="text" name="criteria" value="<%=sCriteria%>" /><br />
<INPUT type="submit" value="Submit" id="submit1" />
</form>
<HR>
<%
'handle the search and display results here
%>
</BODY>
</HTML>

startbar
02-20-2005, 08:40 PM
thanks for the example, i put the code you gave me into a blank asp file and ran it and it didnt do anything (500 error)

How do i implement this form to my database?

Does it work like this - someone picks a category like Plumber and then the Criteria is like the keyword so it will search the database for that keyword within the entries of that category?

How do i implement this form to my database?

Thanks again

miranda
02-20-2005, 10:27 PM
show me your connection string, the name of the databse table, the column that has the category listed, and the column that has the search criteria and i will give you a quick example that you can finish.

miranda
02-20-2005, 10:51 PM
[CODE]
<%@ Language=VBScript %>
<%Option Explicit
Dim sCategory, sCriteria
sCategory = Request.Form("category")
sCriteria = Request.Form("criteria")
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<form method="post" action="<%=Request.ServerVariables("URL")%>">
Search category: <select name="category">
<option value="plumber"<%=If sCategory = "plumber" Then Response.Write " Selected"%>>Plumber</option>
<option value="carpenter"<%=If sCategory = "carpenter" Then Response.Write " Selected"%>>Carpenter</option>
<option value="electrician"<%=If sCategory = "electrician" Then Response.Write " Selected"%>>Electrician</option>
</select><br />
Search Criteria: <INPUT type="text" name="criteria" value="<%=sCriteria%>" /><br />
<INPUT type="submit" value="Submit" id="submit1" />
</form>
<HR>
<%
'....code from your page.....
strSearch = Replace(sCriteria, "'", "''")
strSQL = "SELECT NameCompany, Category, ContactTown, ContactCounty, DescriptionSmall, Keywords, ID, Status " _
& "FROM NETWORK " _
& "WHERE Status=1 " _
& "AND Category ='" & sCategory & "' " _
& "AND (NameCompany LIKE '%" & strSearch & "%' " _
& "OR ContactTown LIKE '%" & strSearch & "%' " _
& "OR Keywords LIKE '%" & strSearch & "%') " _
& "ORDER BY " & ordervariable & " " & sortorder

'....remainder of your code here...
%>
</BODY>
</HTML>

startbar
02-21-2005, 09:46 AM
strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\kunden\homepages\39\d100703461\network\DATABASE.mdb"

The Table is called NETWORK
The search criteria is in the column NameCompany, ContactTown and Keywords

I have a seperate table for called CATEGORY with the categories listing in a column called Category

Hope this is right?

THANK YOU

startbar
02-21-2005, 09:14 PM
bump

Hi thanks again for your patience.

Is that the information you needed?

Thanks

miranda
02-21-2005, 09:30 PM
After I posted mentioning the need to see your connection string etc.... i realized that in an earlier post you had provided it and then posted the code. try that and see how that works

startbar
02-21-2005, 10:11 PM
ok thanks, ill try it and get back to you

THANKS!!

startbar
02-21-2005, 10:18 PM
i tried it,

no joy

Microsoft VBScript compilation error '800a0400'

Expected statement

/network/browse2.asp, line 54

<form method="post" action="<%=Request.ServerVariables("URL")
^


using this code

<%
Const adOpenStatic = 3
Const adLockReadOnly = 1
Const adCmdText = &H0001

Const PAGE_SIZE = 10 ' The size of our pages.

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

Dim iPageCurrent ' The page we're currently on
Dim iPageCount ' Number of pages of records
Dim iRecordCount ' Count of the records returned
Dim I ' Standard looping variable

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("display")
strSearch = Replace(strSearch, "'", "''")

' Retrieve page to show or default to the first
If Request.QueryString("page") = "" Then
iPageCurrent = 1
Else
iPageCurrent = CInt(Request.QueryString("page"))
End If
%>


<html>
<head>

<link rel="stylesheet" href="/network/css.css" type="text/css">


</head>

<body topmargin="0" leftmargin="0" bgcolor="#767676">

<!--#include virtual="/network/header.html"-->

<%
Dim sCategory, sCriteria
sCategory = Request.Form("category")
sCriteria = Request.Form("criteria")
<form method="post" action="<%=Request.ServerVariables("URL")%>">
Search category: <select name="category">
<option value="plumber"<%=if sCategory = "plumber" Then Response.Write " Selected"%>>Plumber</option>
<option value="carpenter"<%=if sCategory = "carpenter" Then Response.Write " Selected"%>>Carpenter</option>
<option value="electrician"<%=if sCategory = "electrician" Then Response.Write " Selected"%>>Electrician</option>
</select><br />
Search Criteria: <INPUT type="text" name="criteria" value="<%=sCriteria%>" /><br />
<INPUT type="submit" value="Submit" id="submit1" />
</form>
%>


<table valign="top" border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
<tr>
<td width="790" style="background-color: #767676; padding: 0px; margin: 0px auto; border: 0px solid #4b4b4b">

<%
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("PATH TO DATABASE.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 & ";"


' Build our query based on the input.

dim ordervariable, sortorder
ordervariable = "NameCompany" 'default column to sort on
sortorder = "ASC" 'default sortorder

if (len(request.querystring("sortby")) >= 1) then
ordervariable = request.querystring("sortby")
end if
if (len(request.querystring("sortorder")) >= 1) then
sortorder = request.querystring("sortorder")
end if

strSearch = Replace(sCriteria, "'", "''")
strSQL = "SELECT NameCompany, Category, ContactTown, ContactCounty, DescriptionSmall, Keywords, ID, Status " _
& "FROM NETWORK " _
& "WHERE Status=1 " _
& "AND Category ='" & sCategory & "' " _
& "AND (NameCompany LIKE '%" & strSearch & "%' " _
& "OR ContactTown LIKE '%" & strSearch & "%' " _
& "OR Keywords LIKE '%" & strSearch & "%') " _
& "ORDER BY " & ordervariable & " " & sortorder

Set rstSearch = Server.CreateObject("ADODB.Recordset")
rstSearch.PageSize = PAGE_SIZE
rstSearch.CacheSize = PAGE_SIZE

rstSearch.Open strSQL, cnnSearch, adOpenStatic, adLockReadOnly, adCmdText

iRecordCount = rstSearch.RecordCount
iPageCount = rstSearch.PageCount

If iRecordCount = 0 Then
' Display no records error.
%>


<title>Startbar.co.uk :: No Results Found</title>


<table cellpadding="5" cellspacing="0" width="100%" height="3" bgcolor="#767676" align="center">
<tr><td width="100%" valign="top" align="left" style="background-color: #4b4b4b; margin: 0px auto;"></td></tr></table>

<table cellpadding="0" cellspacing="0" width="100%" height="2" bgcolor="#cccccc" align="center">
<tr>

<td width="100%" valign="top" align="left" style="background-color: #4b4b4b; margin: 0px auto; border: 0px solid #767676;">

<table cellpadding="0" cellspacing="0" width="99%" height="2" bgcolor="#cccccc" align="center">

<tr>

<td width="100%" height="100%" valign="top" align="left" style="background-color: #5B5A5A; padding: 4px; margin: 0px auto; border: 1px solid #767676;">
<div style="padding-top:5px;padding-bottom:5px;padding-left:5px;padding-right:5px;">
<img src="/network/images/nores.gif"><BR><BR>
<%
if strSearch = "%" then
response.write "No Entries in Database"
else
response.write "but your search for '<b>" & strSearch & "</b>' has returned no results from our database. <BR><BR><b>Search Tips:</b><br>Our search facility uses keywords, categories, company names and towns to return results from the database. Please ensure that all search keywords are spelled correctly and spaced where appropriate. Note that use of symbols can also affect search results!<BR><BR>Please <a href=""/network/search.asp"" class=""tryagain"">click here</a> to go to the advanced search options page"
end if
%>

</div>
</td></tr></table>


</td>

</tr>
</table>

<table cellpadding="5" cellspacing="0" width="100%" height="3" bgcolor="#767676" align="center">
<tr><td width="100%" valign="top" align="left" style="background-color: #4b4b4b; margin: 0px auto;"></td></tr></table>


<%
Else
' Move to the page we need to show.
rstSearch.AbsolutePage = iPageCurrent

' Show a quick status line letting people know where they are:
%>

<%
' 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 cellpadding="5" cellspacing="0" width="100%" height="3" bgcolor="#767676" align="center">
<tr><td width="100%" valign="top" align="left" style="background-color: #4b4b4b; margin: 0px auto;"></td></tr></table>

<title>Startbar.co.uk :: <%
if strSearch = "%" then
response.write "Browsing Network"
else
response.write "Search Results for '" & strSearch & "'"
end if
%></title>

<table cellpadding="0" cellspacing="0" width="100%" height="2" bgcolor="#cccccc" align="center">
<tr>

<td width="100%" valign="top" align="left" style="background-color: #4b4b4b; margin: 0px auto; border: 0px solid #767676;">

<table cellpadding="0" cellspacing="0" width="99%" height="2" bgcolor="#cccccc" align="center">

<tr>

<td width="100%" height="100%" valign="top" align="left" style="background-color: #5B5A5A; padding: 4px; margin: 0px auto; border: 1px solid #767676;">
<div style="padding-top:5px;padding-bottom:5px;padding-left:5px;padding-right:5px;">

<%
if strSearch = "%" then
response.write "<img src=""/network/images/browseheader.gif"">"
else
response.write "<img src=""/network/images/yoursearch.gif"">"
end if
%>
<BR>
<%
if strSearch = "%" then
response.write "You are currently browsing all company entries totalling " & iRecordCount & "."
else
response.write "<BR>Your search for '<b>" & strSearch & "</b>' returned " & iRecordCount & " result(s)."
end if
%>

</div>
</td></tr></table>


</td>

</tr>
</table>

<table cellpadding="5" cellspacing="0" width="100%" height="3" bgcolor="#767676" align="center">
<tr><td width="100%" valign="top" align="left" style="background-color: #4b4b4b; margin: 0px auto;"></td></tr></table>

<table cellpadding="0" cellspacing="0" width="100%" height="2" bgcolor="#cccccc" align="center">
<tr>
<td width="100%" valign="top" align="left" style="background-color: #4b4b4b; margin: 0px auto; border: 0px solid #767676;">

<table cellpadding="0" cellspacing="0" width="99%" height="2" bgcolor="#cccccc" align="center">

<tr>

<td width="10%" height="100%" valign="top" align="left" style="background-color: #4b4b4b; padding: 4px; margin: 0px auto; border: 0px solid #767676;">
<div style="padding-top:3px;padding-bottom:3px;padding-left:6px;padding-right:6px;"><B>Sort By:</B></div></td>

<td width="74%" height="100%" valign="top" align="left" style="background-color: #4b4b4b; padding: 4px; margin: 0px auto; border: 0px solid #767676;">
<div style="padding-top:3px;padding-bottom:3px;padding-left:6px;padding-right:6px;"><%
if strSearch = "%" then
response.write "<a href=""browse.asp?display=" & strSearch & "25&page=" & iPageCurrent & "&sortby=NameCompany&sortorder=ASC"" class=""menu"">Company Name</a> / <a href=""browse.asp?display=" & strSearch & "25&page=" & iPageCurrent & "&sortby=Category&sortorder=ASC"" class=""menu"">Category</a>"
else
response.write "<a href=""browse.asp?display=" & strSearch & "&page=" & iPageCurrent & "&sortby=NameCompany&sortorder=ASC"" class=""menu"">Company Name</a> / <a href=""browse.asp?display=" & strSearch & "&page=" & iPageCurrent & "&sortby=Category&sortorder=ASC"" class=""menu"">Category</a>"
end if
%></div></td>

<td width="16%" height="100%" valign="top" align="left" valign="center" style="background-color: #4b4b4b; padding: 4px; margin: 0px auto; border: 0px solid #767676;"><div style="padding-top:3px;padding-bottom:3px;padding-left:6px;padding-right:6px;"><%
if strSearch = "%" then
response.write "<a href=""browse.asp?display=" & strSearch & "25&page=" & iPageCurrent & "&sortby=ContactTown&sortorder=ASC"" class=""menu"">Location</a>"
else
response.write "<a href=""browse.asp?display=" & strSearch & "&page=" & iPageCurrent & "&sortby=ContactTown&sortorder=ASC"" class=""menu"">Location</a>"
end if
%></div></td>

</tr></table>


</td>

</tr>
</table>



<table cellpadding="5" cellspacing="0" width="100%" height="3" bgcolor="#767676" align="center">
<tr><td width="100%" valign="top" align="left" style="background-color: #4b4b4b; margin: 0px auto;"></td></tr></table>




<%
Do While Not rstSearch.EOF And rstSearch.AbsolutePage = iPageCurrent
%>

<table cellpadding="0" cellspacing="0" width="100%" height="2" bgcolor="#cccccc" align="center">
<tr>

<td width="100%" valign="top" align="left" style="background-color: #4b4b4b; margin: 0px auto; border: 0px solid #767676;">

<table cellpadding="0" cellspacing="0" width="99%" height="2" bgcolor="#cccccc" align="center">

<tr>

<td width="10%" height="100%" valign="top" align="left" valign="center" style="background-color: #5B5A5A; padding: 0px; margin: 0px auto; border-top: 1px solid #767676; border-bottom: 1px solid #767676; border-left: 1px solid #767676; border-right: 1px solid #767676;"><%
dim fileName
fileName = rstSearch.Fields("NameCompany")
if fileName = "" or IsNull(fileName) then
response.write "<img src=""/network/images/small/no.gif"">"
else
response.write "<img src=""/network/images/small/" & fileName & ".gif"">"
end if
%></td>

<td width="74%" height="100%" valign="top" align="left" style="background-color: #5B5A5A; padding: 4px; margin: 0px auto; border-top: 1px solid #767676; border-bottom: 1px solid #767676; border-right: 0px solid #767676;">
<div style="padding-top:5px;padding-bottom:5px;padding-left:6px;padding-right:6px;">

<img src="/network/images/companyarrow.gif"> <a class="menu1" href="company.asp?view=viewcompany&ID=<%= rstSearch.Fields("ID").Value %>"><%= rstSearch.Fields("NameCompany").Value %></a> ( <a class="browse-category" href="/network/catselect.asp?category=<%= rstSearch.Fields("Category").Value %>"><%= rstSearch.Fields("Category").Value %></a> )<BR>
<%= rstSearch.Fields("DescriptionSmall").Value %><BR>


</div>
</td>


<td width="16%" height="100%" valign="center" align="left" valign="center" style="background-color: #5B5A5A; padding: 0px; margin: 0px auto; border-top: 1px solid #767676; border-bottom: 1px solid #767676; border-left: 1px solid #767676; border-right: 1px solid #767676;">
<div style="padding-top:5px;padding-bottom:5px;padding-left:6px;padding-right:6px;">
<a class="browse-category" href="/network/browse.asp?display=<%= rstSearch.Fields("ContactTown").Value %>"><%= rstSearch.Fields("ContactTown").Value %></a></div></td>



</tr></table>


</td>

</tr>
</table>



<table cellpadding="5" cellspacing="0" width="100%" height="3" bgcolor="#767676" align="center">
<tr><td width="100%" valign="top" align="left" style="background-color: #4b4b4b; margin: 0px auto;"></td></tr></table>

<%

rstSearch.MoveNext
Loop
%>





<table cellpadding="0" cellspacing="0" width="100%" height="2" bgcolor="#cccccc" align="center">
<tr>

<td width="100%" valign="top" align="left" style="background-color: #4b4b4b; margin: 0px auto; border: 0px solid #767676;">

<table cellpadding="0" cellspacing="0" width="99%" height="2" bgcolor="#cccccc" align="center">

<tr>

<td height="100%" valign="top" align="left" style="background-color: #4b4b4b; padding: 4px; margin: 0px auto; border-bottom: 1px solid #5B5A5A;">
<div style="padding-top:1px;padding-bottom:1px;padding-left:1px;padding-right:1px;">



Displaying Page <font class="cpage"><%=iPageCurrent%> of <%=iPageCount%> </font>
</font>

</div>
</td>

<td height="100%" valign="top" align="right" style="background-color: #4b4b4b; padding: 4px; margin: 0px auto; border-bottom: 1px solid #5B5A5A;">

<div style="padding-top:1px;padding-bottom:1px;padding-left:1px;padding-right:1px;">
<%
' Now we need to show our navigation links:

' Show "previous" and "next" page links which pass the page to
' view our search parameter. You could also use form buttons
' but I find this looks better.
If iPageCurrent > 1 Then
%>


<img src="/network/images/previouspage.gif" border="0"> <a href="<%= strURL %>?display=<%= Server.URLEncode(strSearch) %>&page=<%= iPageCurrent - 1 %>&sortby=<%=ordervariable%>&sortorder=<%=sortorder%>" class="menu">Previous Page</a>
<%
End If

' You can also show page numbers:
For I = 1 To iPageCount
If I = iPageCurrent Then
%>
<img src="/network/images/pagedivider.gif" border="0">
<%
Else
%>

<%
End If
Next 'I

If iPageCurrent < iPageCount Then
%></font>
<a href="<%= strURL %>?display=<%= Server.URLEncode(strSearch) %>&page=<%= iPageCurrent + 1 %>&sortby=<%=ordervariable%>&sortorder=<%=sortorder%>" class="menu"> Next Page</a> <img src="/network/images/nextpage.gif" border="0">

</div>
</td>

</tr></table>

</td>

</tr>
</table>

<% End If %>

<%
End If

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


<table cellpadding="5" cellspacing="0" width="100%" height="3" bgcolor="#767676" align="center">
<tr><td width="100%" valign="top" align="left" style="background-color: #4b4b4b; margin: 0px auto;"></td></tr></table>



</td>


<table cellpadding="0" cellspacing="0" width="780" height="2" bgcolor="#4b4b4b" align="center">

<tr>

<td width="100%" valign="top" align="left" style="background-color: #4b4b4b; padding: 4px; margin: 0px auto;">

<!--#include virtual="/network/footer.html"-->

</td>

</tr>
</table>


</div>


</body>
</html>

miranda
02-23-2005, 07:16 AM
This is why using inline coding sucks and should be done away with as much as possible. And also why it helps to indent. You are missing a closing delimeter before you have an opening delimiter.


<%
Dim sCategory, sCriteria
sCategory = Request.Form("category")
sCriteria = Request.Form("criteria")
%>
<form method="post" action="<%=Request.ServerVariables("URL")%>">

startbar
02-23-2005, 06:22 PM
hi, it still doesnt work (with the code i gave in last post) even with the closing delimeter!

help please!

Sorry!!

miranda
02-23-2005, 07:33 PM
What error if any were you given?

startbar
02-23-2005, 08:38 PM
500 page cannot be found

miranda
02-23-2005, 08:58 PM
500 is a very generic error what does the server log say? Also in your Internet Options under the Advanced tab unclick the box next to Show friendly HTTP error messages.