Sunday 14 Mar 2010   
Add Comment

Select like with cfqueryparam

ColdFusion Tutorial #41

cfqueryparam is a fantastic part of ColdFusion it helps protect from SQL injection and improves performance. It is a little differnt to use then normal querys and one question that often gets asked is "How do I do a like clause with cfqueryparam?". Well here is the answer. line 4 of search_result.cfm <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="%#FORM.keyword#%">

Remember the % % goes around the varibale ( or plain text string )

demo.cfm

Query the database for some sample data and show a simple form.

 
 


search_results.cfm

Using the data posted retrive the results from the database that are "like" the term entered.

 
 


Demo

See this code running!


Download

Download this code as a zip!


Comments

Hi John,
You don't need the #'s in the CFIF statement on the search_results.cfm page.
Cheers
Matthew
Matthew @ Tuesday 09 Mar 2010 - 01:33:15 PM

Hi,
yep you are right:)
Thanks for noticing this,and that error is fixed!
thanks,
Johnny
John Barrett @ Wednesday 10 Mar 2010 - 06:19:20 PM

Click button to add a comment


Author

John Barrett


Published

Monday 31 Aug 2009

Tags

cfelse  cfform  cfif  cfinput  cfoutput  cfquery  cfqueryparam  cfselect 

convert dvd to ipod converter psp   Winnipeg Colleges   Free debt consolidation loan services.   SSAT Prep   Tutorial Jobs for Felons Online   Discount cigarettes   online MBA degree   EMF Financial   Sharath Sury