Created
July 13, 2012 18:20
-
-
Save cfjedimaster/3106450 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
//Default our returnformat to json | |
url.returnformat="json"; | |
remote array function searchArt(required string term) { | |
var q = new com.adobe.coldfusion.query(); | |
q.setDatasource("cfartgallery"); | |
q.setSQL("select artid, artname, description, price, largeimage, firstname, lastname, mediatype " & | |
"from art left join artists on art.artistid = artists.artistid " & | |
"left join media on art.mediaid = media.mediaid " & | |
"where lower(artname) like :search or lower(description) like :search or lower(mediatype) like :search"); | |
q.addParam(name="search",value="%#lcase(arguments.term)#%",cfsqltype="cf_sql_varchar"); | |
var queryResult = q.execute().getResult(); | |
var results = []; | |
if(!queryResult.recordCount) return results; | |
for(var i=1; i<=queryResult.recordCount; i++) { | |
arrayAppend(results, { | |
"id":queryResult.artid[i], | |
"name":queryResult.artname[i], | |
"description":queryResult.description[i], | |
"price":queryResult.price[i], | |
"artist":queryResult.firstname[i] & " " & queryResult.lastname[i], | |
"media":queryResult.mediatype[i], | |
"image":"/cfdocs/images/artgallery/" & queryResult.largeimage[i] | |
}); | |
} | |
return results; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment