Copy link to clipboard
Copied
I'm using Coldfusion 9, stand alone. I'm attempting to pull all fields from a table to display as a list, but if a table field is empty I don't want to display that field. I tried using <cfif ParameterExists> for each field but my list returned as a jumbled mess. Here's the code I'm using:
<table width="405px">
<tr>
<td id="family">#Family#</td>
</tr>
<tr>
<td id="line">#Line#</td>
</tr>
<tr>
<td id="model">
<cfif #ParameterExists(Procs.Model1)# IS "yes"><cfoutput>#Procs.Model1#<br></cfoutput><cfelse></cfif>
<cfif #ParameterExists(Procs.Model2)# IS "yes"><cfoutput>#Procs.Model2#<br></cfoutput><cfelse></cfif>
<td>
</tr>
</table>
Thanks for your help!
<Bryan> wrote:
I think the last statement you made might be closer to my situation, "model1" is a column in my recordset. There are seven of these that may or maynot have data in them.
That right there is a clear statement of a database design the needs to be normalized. You shouldn't have seven columns for models. (What happens the first time this database needs to store eight models for a family?) You should have a models table that has rows for each model connected to the family recor
...Copy link to clipboard
Copied
OK, first things first, don't use parameterExists(); use structKeyExists(). paremeterExists() is deprecated (and has been for getting close to ten years now!). Secondly, you don't need the <cfelse> if you have no ELSE condition. However neither of those will cause you the problems you want fixing.
Can you quantify "returned as a jumbled mess"? Perhaps with a screen cap? And a description of what you want, and how that differs from what you are getting.
One thing you do have which is less than idea is your "header" has two table columns, but the "detail" row only has one. And you don't seem to be actually looping over a recordset, which is probably what you want to be doing..?
And, given you are perhaps supposed to be looping over a recordset, you dopn't want to be doing either parameterExists() or structKeyExists(), because provided "Model1" is a column in recordset "Procs", then it will always exist. You probably want to check for an empty string, not whether it exists.
--
Adam
Copy link to clipboard
Copied
Here's a screen of what my code returns:
This is what I would like it to look like minus the extra spaces beneath the models due to empty fields in the table:
I think the last statement you made might be closer to my situation, "model1" is a column in my recordset. There are seven of these that may or maynot have data in them. I don't want to display the ones that don't have data in them in order to eliminate the extra spacing. Please forgive the old CF code, it's been about 10 years since I've last used Coldfusion and haven't kept up with the new tags.
Copy link to clipboard
Copied
<Bryan> wrote:
I think the last statement you made might be closer to my situation, "model1" is a column in my recordset. There are seven of these that may or maynot have data in them.
That right there is a clear statement of a database design the needs to be normalized. You shouldn't have seven columns for models. (What happens the first time this database needs to store eight models for a family?) You should have a models table that has rows for each model connected to the family record with a foreign key. Then it would be a simple matter of a SQL join statement and a <cfoutput group....> recordset loop to output the display you want.
But if you are unwilling or unable to professionally normalize your database design. You are not checking for missing "parameters' or "structure keys". They will never be missing. All seven columns will always exist in the record set, if you select them from the database.
What you need to be checking for is "empty" values. ColdFusion record sets don't really have NULL values, so just check for empty strings.
<cfif len(trim(proces.model1) IS NOT 0><cfoutput>#Procs.Model1#<br></cfoutput></cfif>
Copy link to clipboard
Copied
You're right, I was going about this all wrong. My database needs to be normalized first, using a separate table for the models. It's been too long and I overlooked that. Thanks!
Copy link to clipboard
Copied
It's also worth saying that you don't need the pound signs in the cfif
anymore, and you should minimize the number of CFOUTPUT. I've run some
recent experiments and you'll find you'll get a performance
improvement if you have less of them vs. more. It depends how many
CFOUTPUTs you have as far as how much of an improvement you'll get,
but there is one regardless.
Change this:
</cfoutput
Copy link to clipboard
Copied
You will have to let us know what Family, Line, Procs, model1 and model2 are, so that we can figure out what you're trying to do.