Entries for month: September 2005

Selecting a random row in ColdFusion

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)>

No Comments

ColdFusion MX 7.0.1 Updater Released

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!

No Comments

Creating cookies available to different servers

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.

No Comments

Check password fields in Flash Forms

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>

No Comments

How to kill sessions in ColdFusion

There are many ways to kill entire sessions in ColdFusion... this is my favorite:

<cfloop collection="#Session#" item="sessionVar">
   <cfset StructDelete(Session, sessionVar)>
</cfloop>

No Comments