Avatar of Elizabeth2
Elizabeth2
Flag for United States of America asked on

ColdFusion Help displaying default value

I'm searching a MySQL database using ColdFusion that has some empty fields within the database table. These empty fields display in an HTML table on the results page, as just being empty. What I'd like to do is to have the word "none" display if there is no value in the database for that field or column. In other words, I'd like to code my page to have the word "none" appear in place of those empty returns within my table.

Here is the search:
http://flashdesyne.com/wilsoncabinetry/search.cfm

Enter this model number: ET0444-O

Notice that the column for "Model Finish" is empty.

I'd like to have "none" appear in that column.

I tried cfparam with default as "none" but that didn't work.

Could someone please help me?

Thank you in advance.

elizabeth
ColdFusion Language

Avatar of undefined
Last Comment
Chris Ashcraft

8/22/2022 - Mon
Elizabeth2

ASKER
Thanks to some previous posts, I figured this out using:

<cfif NOT Len(Trim(myqueryname.model_finish))>
<cfset myqueryname.model_finish = "none">
</cfif>
ASKER CERTIFIED SOLUTION
Coast Line

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
gdemaria

This isn't correct..
<cfif NOT Len(Trim(myqueryname.model_finish))>
   <cfset myqueryname.model_finish = "none">
</cfif>

You cannot assign a value to a query column, although you could use the query set cell function.

<cfparam..> doesn't work because it does not test for empty, it tests for a non-existant variable...

Here's how you can do it..

In your select statement you can do this..

 select isNull(model_finihs,'none') as model_finish
       , ...
 from table...

Or when displaying you can use a CFIF statement..

<cfif Len(Trim(myqueryname.model_finish))>
   #myqueryname.model_finish#
<cfelse>
   none
</cfif>
Chris Ashcraft

You can do this in one line with IIF...

<cfoutput>
#IIF(LEN(TRIM(myqueryname.model_finish)), DE(myqueryname.model_finish), DE("none"))#
</cfoutput>

Open in new window

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Coast Line

btw using IIF will effect Performance of the page, So i will not recommend it
Chris Ashcraft