Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: SQL SELECT PROBLEM


Message #1 by "Dale Wright" <dwright@c...> on Mon, 27 Jan 2003 14:26:03
Hi....

I have a paging page that uses users inputted text to search a database 
table. The records are displayed using a paging system.....If a user 
searches for say... DALE & TOM....When the user clicks on the next button 
of the paging feature, the Paging system looks for JUST TOM and Not 
DALE....So it is missing the search criteria...

I have a SQL statement that search the field until all words have been 
accounted for....This is the Statement:

			sql = "SELECT * FROM FAQAnswer WHERE "
							Do Until instr
(StrSearch, " ") = 0
							sql = sql & "FAQ 
Like '%" _
								& left
(StrSearch, instr(StrSearch," ") - 1) & "%' OR "
								
	StrSearch = Right(StrSearch, len(StrSearch) - instr(StrSearch," "))
					Loop
		
							If len(StrSearch) 
> 1 Then
								
	sql = sql & "FAQ Like '%" & StrSearch & "%'"
							Else
								    sql = 
Left(sql, Len(sql) - 4)
				End if


AND THIS IS THE PAGING LINK:

 If cInt(intPage) > 1 Then
                    
                         Response.Write "<td><a href=bk_searchresult.asp?
NAV=" & intPage - 1&"&FIND=" & StrSearch & "&srchType=" & Request
("srchType") & "><< Prev</a></td>"
                    End IF
                    

Would love to here from anyone who knows what i am doing wrong!!!

Regards

Dale
Message #2 by pgtips@m... on Wed, 29 Jan 2003 10:08:26
Hi Dale,

it looks like you are using a space to separate the different search terms 
in strSearch.  If so, you need to use Server.URLEncode(strSearch) before 
you can include it in your <a> tag.  Its good practice to put your 
attribute values in quotes too, i.e. <a href="...">

Also, the split() function would be a neater way of building your sql:
For Each strTerm in Split(strSearch, " ", -1, 1)
  sql = sql & "FAQ LIKE '%" & strTerm & "%' OR "
Next

Finally, I hope you are filtering out (or escaping) characters like ' in 
strSearch...
hth
Phil
>----------------------------------------------
> Hi....

> I have a paging page that uses users inputted text to search a database 
t> able. The records are displayed using a paging system.....If a user 
s> earches for say... DALE & TOM....When the user clicks on the next 
button 
o> f the paging feature, the Paging system looks for JUST TOM and Not 
D> ALE....So it is missing the search criteria...

> I have a SQL statement that search the field until all words have been 
a> ccounted for....This is the Statement:

> 			sql = "SELECT * FROM FAQAnswer WHERE "
	> 						Do Until instr
(> StrSearch, " ") = 0
	> 						sql = sql & "FAQ 
L> ike '%" _
	> 							& left
(> StrSearch, instr(StrSearch," ") - 1) & "%' OR "
	> 							
	> StrSearch = Right(StrSearch, len(StrSearch) - instr
(StrSearch," "))
	> 				Loop
	> 	
	> 						If len(StrSearch) 
>>  1 Then
	> 							
	> sql = sql & "FAQ Like '%" & StrSearch & "%'"
	> 						Else
	> 							    sql = 
L> eft(sql, Len(sql) - 4)
	> 			End if

> 
A> ND THIS IS THE PAGING LINK:

>  If cInt(intPage) > 1 Then
 >                    
 >                         Response.Write "<td><a href=bk_searchresult.asp?
N> AV=" & intPage - 1&"&FIND=" & StrSearch & "&srchType=" & Request
(> "srchType") & "><< Prev</a></td>"
 >                    End IF
 >                    

> Would love to here from anyone who knows what i am doing wrong!!!

> Regards

> Dale
Message #3 by "Dale Wright" <dwright@c...> on Wed, 29 Jan 2003 13:59:18
Thanks for the reply phil...

now sorted.....Problem was i needed to add an hidden field to search for a 
specific type, ie text / dept.... Yeah i am filtering out '....

Regards

Dale

  Return to Index