Entries for month: September 2005
Selecting a random row in ColdFusion
Posted by David in ColdFusion on September 29, 2005
I've had the need to select a random record from a table within a ColdFusion app and I found two ways of doing this...
1. If using MS SQL Server, use the newID() function. MS SQL Server creates a guid for each row with each query that it uses internally to track the rows - independent of the primary key. Here is an example:
<cfquery name="query1" datasource="your_datasource">
SELECT TOP 1 *
FROM tbl_name
ORDER BY newID()
</cfquery>
2. Use ColdFusion to select a random record for you. In this process you use RandRange() to do the work for you. Here is an example:
<cfquery name="query1" datasource="your_datasource">
SELECT *
FROM tbl_name
</cfquery>
<cfset randomRow = RandRange(1,query1.RecordCount)>
ColdFusion MX 7.0.1 Updater Released
Posted by David in ColdFusion on September 28, 2005
The release of the ColdFusion MX 7.0.1 Updater has set off a pretty big blog-storm... so I might as well blog about it myself =). You can get the updater here.
There are alot of enhancements to this update so I would recommend you update as soon as you can. You can also find the updated ColdFusion MX 7.0.1 Report Builder on that page as well!
Creating cookies available to different servers
Posted by David in ColdFusion on September 26, 2005
I recently ran into a situation where i had to define certain variables and make their data available to apps on different servers. The way i went about in doing this is to create a cookie available to that certain domain. I used the "domain" attribute in the cfcookie tag.
<cfcookie name="appName.IsLoggedIn" value="True" domain=".dcfusion.com">
Some things to remember are that you must start with a period. If the value is a subdomain, the valid domain is all domain names that end with this string. This attribute sets the available subdomains on the site upon which the cookie can be used.
For a domain value that ends in a country code, the specification must contain at least three periods; for example, ".mongo.state.us". For top-level domains, two periods are required; for example, ".mgm.com".
You cannot use an IP address as a domain.
Check password fields in Flash Forms
Posted by David in ColdFusion on September 12, 2005
Here is a quick way to check password fields to see if they match in Flash Forms:
<cfform format="Flash" onSubmit="if( p1.text != p2.text ){ alert('Passwords Do Not Match!'); return false;}">
<cfinput type="password" name="p1">
<cfinput type="password" name="p2">
<cfinput type="Submit" name="btn" value="save">
</cfform>
How to kill sessions in ColdFusion
Posted by David in ColdFusion on September 8, 2005
There are many ways to kill entire sessions in ColdFusion... this is my favorite:
<cfloop collection="#Session#" item="sessionVar">
<cfset StructDelete(Session, sessionVar)>
</cfloop>
Recent Comments