Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Search for MULTIPLE words within ONE field??
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Search for MULTIPLE words within ONE field??

 Post Reply Post Reply
Author
bigchetti View Drop Down
Newbie
Newbie


Joined: 28 December 2007
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote bigchetti Quote  Post ReplyReply Direct Link To This Post Topic: Search for MULTIPLE words within ONE field??
    Posted: 28 December 2007 at 9:35am

Hey guys,

I've created my first search page using ASP. Whilst the search function works and data can be obtained, the results will only be successful if the word i try to search is the first word in any entry in one field.

For example...

if i search for BALL

i will get nothing...

however if i search for GLOW BALL i will get a result

i will receive a result...

similarly if i search for GLOW i will get multiple results?
How can i structure the query so that i can search for any of the words within the field and be guaranteed to get a result?

the link for the search form is

http://www.galaxyworldimports.com.au/search.html


Thanks for any help!!

 

a sample of the asp code is listed below:

]<%
 'Open up a connection to our Access Database
 'that stores the customer information.
 Set MyConn = Server.CreateObject("ADODB.Connection")
      MdbFilePath = Server.MapPath("Databases/gal_imports.mdb")
      MyConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"
      
 'Read in the charactes the user entered
 Dim strProductNameQ
 strProductNameQ = Trim(Request("ProductNameQ"))
 
 'Create our SQL statenebt variable
 Dim strSQL
 strSQL = "SELECT ProductName, ProductPrice FROM Products WHERE ProductName LIKE '" & _
  strProductNameQ & "%' ORDER BY ProductName"
 
 'Create a recordset object instance, and execute the SQL Statement
 Dim objRS
 Set objRS = Server.CreateObject("ADODB.Recordset")
 objRS.Open strSQL, MyConn
 
 'Determine whether or not there are any records in objRS
 If objRS.EOF then
  'No records were returned for the characters entered by the user
  Response.Write "There are no products that contain " & _
   UCase(strProductNameQ)
  
 Else
  'There are one or more products that meet the condition entered by the
  'user. Display these products...
  
  Response.Write "<B>A Listing of Products beginning with " & _
   UCase(strProductNameQ) & ":</B><BR>"
  
  Do While Not objRS.EOF
   Response.Write objRS("ProductName") & " - " & _
     FormatCurrency(objRS("ProductPrice")) & "<BR>"
     
  
   'Move on to the next customer
   objRS.MoveNext
  Loop
 End If
 
 'Clean up our ADO objects
 objRS.Close
 Set objRS = Nothing
 
 MyConn.Close
 Set MyConn = Nothing
 
 %>

 

 

Back to Top
Scotty32 View Drop Down
Moderator Group
Moderator Group


Joined: 30 November 2002
Location: Manchester, UK
Status: Offline
Points: 1682
Post Options Post Options   Thanks (0) Thanks(0)   Quote Scotty32 Quote  Post ReplyReply Direct Link To This Post Posted: 28 December 2007 at 12:03pm
if you look at the following (the SQL Statement)

  strSQL = "SELECT ProductName, ProductPrice FROM Products WHERE ProductName LIKE '" & _ 
  strProductNameQ & "%' ORDER BY ProductName"


the part is red (%) is the wildcard, which in this case says find everything that starts with search term.

if you did

  strSQL = "SELECT ProductName, ProductPrice FROM Products WHERE ProductName LIKE '%" & _ 
  strProductNameQ & "%' ORDER BY ProductName"


it will find all instances of the word. so if you searched for ball, it will find it if its the first, last or middle word.

if you delete the % at the end, it will basically do find all records that end in search term.

hope that helps.
S2H.co.uk - WebWiz Mods and Skins

For support on my mods + skins, please use my forum.
Back to Top
bigchetti View Drop Down
Newbie
Newbie


Joined: 28 December 2007
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote bigchetti Quote  Post ReplyReply Direct Link To This Post Posted: 28 December 2007 at 12:06pm
Thanks that works perfectly! Greatly appreciated!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.