Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP 3.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 23rd, 2004, 09:37 PM
Registered User
 
Join Date: Sep 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Searching the database...HELP!

Chapter 13 has an example of DB search code 'Who Directed What?'
This works well with my site..BUT,
What code is needed to extend the search to multiple fields?
e.g. Director Name & Name of Film etc.
  #2 (permalink)  
Old September 24th, 2004, 02:12 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,

I am not sure about the code that you have used. But I can assume things here to help you out.

You should add another text field for "Name of Film" in the HTML form.

Then the querystring should be constructed such that it searches for both Director name and Name of Film.

Not sure how you would like to use the condition there, I mean if you would want to go for AND operation or and OR operation.

Sql statement would look like.
Select COLUMNLIST from TABLE where DirectorName like '%FORM_TEXTFIELD_VALUE%' AND NameofFilm like '%FORM_TEXTFIELD_VALUE%'

As I don't have that book, it would be better if you could post some related code where you face problem.

Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
  #3 (permalink)  
Old September 25th, 2004, 12:04 AM
Registered User
 
Join Date: Sep 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Seems the code I used was to only select the first record anyway.
eg.
<%
Dim strDirector, strCriteria
strDirector = Request.Form("director")

Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "AllMovies", strConnect, adOpenStatic, AdLockReadOnly, adCmdTable

strCriteria = "Director='" & strDirector & "'"

objRS.Find strCriteria
If objRS.EOF Then
Reponse.Write " Blah Baah Blah " & _
strDirector
Else
Response.Write "Blah Blah Blah " & _

End If
objRS.Close
Set objRS = Nothing
%>

What I want to do is search for numerous things from my data base.
e.g Director & film & year etc.


I think I will need to use the Filter

Any ideas?



  #4 (permalink)  
Old September 25th, 2004, 10:21 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Yes, you got to use filter. FIND finds the first record that matches the criteria.
Code:
objRS.Filter = "Director='" & strDirector & "'"
Set objFilter = objRS
Now objFilter hold the records that match your criteria. Loop through that to process the matched records.

Use AND / OR operators to specify multiple conditions for FILTER.
Eg:
Code:
objRS.Filter = "Director='" & strDirector & "' AND Film='" & strFilm & "'"
Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
  #5 (permalink)  
Old September 26th, 2004, 07:46 PM
Registered User
 
Join Date: Sep 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for that...BUT
I still can't get my head around it all.
Perhaps you could suggest the 'full' replacement code from the one I provided.
I think my problem is getting the right Dim and str codes etc.

Thanks

Z.

  #6 (permalink)  
Old September 30th, 2004, 09:45 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Code:
<%
Dim strDirector, strCriteria, strFilm
strDirector = Request.Form("director")
strFilm = Request.Form("Film")
Assuming that you have the Film field defined on the Form, else use the one that you have defined

Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "AllMovies", strConnect, adOpenStatic, AdLockReadOnly, adCmdTable

strCriteria = "Director='" & strDirector & "' AND Film='" & strFilm & "'"

objRS.Filter = strCriteria
If objRS.EOF Then
Reponse.Write " Blah Baah Blah " & _
strDirector
Else
Response.Write "Blah Blah Blah " & _

End If
objRS.Close
Set objRS = Nothing
%>
Hope this explains.
Cheers!

_________________________
- Vijay G
Strive for Perfection
  #7 (permalink)  
Old September 30th, 2004, 09:52 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Instead, you could also achieve that in this way.
Code:
<%
Dim strDirector, strCriteria, strFilm, strSQL
strDirector = Request.Form("director")
strFilm = Request.Form("Film")
Assuming that you have the Film field defined on the Form, else use the one that you have defined

Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
strSQL = "select * from AllMovies where Director='" & strDirector & "' AND Film='" & strFilm & "'"
objRS.Open strSQL, strConnect, adOpenStatic, AdLockReadOnly, adCmdText

'Hope that you use a WHILE loop below to loop through the resultset to get them all deisplay in the format you wanted.
If objRS.EOF Then
Reponse.Write " Blah Baah Blah " & _
strDirector
Else
Response.Write "Blah Blah Blah " & _

End If
objRS.Close
Set objRS = Nothing
%>
_________________________
- Vijay G
Strive for Perfection


Similar Threads
Thread Thread Starter Forum Replies Last Post
searching a database mark jonas MySQL 13 January 19th, 2007 10:01 AM
Searching through a database d5t ASP.NET 1.0 and 1.1 Basics 6 October 27th, 2006 07:10 AM
help with Database searching europhreak Classic ASP Basics 1 February 8th, 2006 07:30 AM
Searching trough a database toni_montana PHP How-To 2 September 25th, 2004 09:17 AM
searching a database shabazzk Classic ASP Databases 2 March 10th, 2004 06:56 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.