Since the browser doesn’t care about the file extension, I could also do:
<cfset news = queryNew("articleurl,title,category")>
<cfloop index="x" from="1" to="20">
<cfset newurl = "http://someurl.com/#x#.html">
<cfset newtitle = "News Story #x#">
<cfset newcategory = listGetAt("Cats,Dogs",randRange(1,2))>
<cfset querySetCell(news, "articleurl", newurl)>
<cfset querySetCell(news, "title", newtitle)>
<cfset querySetCell(news, "category", newcategory)>
Obviously this stuff would be a “real” database hit. Next I want to allow folks to filter both by a max number of entries as well as by category:
<cfparam name="url.max" default="10">
<cfparam name="url.category" default="">
<!— handle getting right data —> <cfquery name=”news” dbtype=”query” maxrows=”#url.max#”> select * from news <cfif url.category is not ““> where lower(category) = <cfqueryparam cfsqltype=”cf_sql_varchar” value=”#lcase(url.category)#”> </cfif> </cfquery> </code>
Nothing too complex about that so I won’t cover it in detail. I will mention one tip about maxrows however. If you pass a maxrows of -1, it is the same as all rows. This is a handy way to use maxrows and still allow folks to not specify a maximum number of rows.
document.write("<table border='1' bgcolor='yellow'><tr><td>");
document.write("<a href='#articleurl#'>#title#</a> [#category#]<br>");
As you can see, I used a simple table to output the query. Now if you wanted to embed this on your site, you would just use this syntax to get 4 Cat stories
Or this syntax to get 10 stories on dogs and cats.
Pretty simple stuff, but you can make it more complex of course. Does anyone have any examples of this they would like to share?