Skip to main content
Known Participant
December 13, 2010
Answered

ParameterExist Question

  • December 13, 2010
  • 2 replies
  • 696 views

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!

    This topic has been closed for replies.
    Correct answer ilssac

    &lt;Bryan&gt; 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>

    2 replies

    BKBK
    Community Expert
    Community Expert
    December 13, 2010

    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.

    Inspiring
    December 13, 2010

    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

    _Bryan_Author
    Known Participant
    December 13, 2010

    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.

    ilssac
    ilssacCorrect answer
    Inspiring
    December 13, 2010

    &lt;Bryan&gt; 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>