Skip to content

Instantly share code, notes, and snippets.

@andrew-dixon
Created June 3, 2014 15:14
Show Gist options
  • Select an option

  • Save andrew-dixon/f4a02cd55350e9a79f96 to your computer and use it in GitHub Desktop.

Select an option

Save andrew-dixon/f4a02cd55350e9a79f96 to your computer and use it in GitHub Desktop.
<cfparam name="URL.searchTerm" default="">
<!DOCTYPE html>
<html lang="en">
<head>
<title>This is my example..</title>
</head>
<body>
<form action="example.cfm" method="GET">
<label for="searchTerm">Search: </label>
<input type="text" name="searchTerm" id="searchTerm" value="<cfoutput>#Form.searchTerm#</cfoutput>"/>
<input type="submit"/>
</form>
<cfif URL.searchTerm NEQ "">
<cfquery name="searchResults">
SELECT
content.c_id,
content.c_title,
content.c_url
FROM
content
WHERE
c_title LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="%#URL.searchTerm#%">
</cfquery>
<cfif searchResults.recordCount GT 0>
<div>#searchResults.recordCount# Results</div>
<div>
<cfloop query="searchResults">
<div>
<cfoutput><a href="#searchResults.c_url#">#searchResults.c_title#</a></cfoutput>
</div>
</cfloop>
</div>
<cfelse>
<div>No Results</div>
</cfif>
</cfif>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment