CFIF is being ignored

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default CFIF is being ignored

    I have 2 cfif statements at the head of my doc that are being ignored in the
    output. Only the efelse part of the statements are being read. I have
    attached the code and I would really appreciate some insight as to why it's
    being ignored.

    In the first statement only the First part of the cfif is being output for
    all instances. And the 2nd cfif statement only the last part is being output
    for all instances.

    Thanks,
    Kim
    Here is the recordset, and the cfif statements:

    <cfquery name="rsGetEmployeeList" datasource="#request.dsn#">
    SELECT yda_Employees.Emp_ID, yda_Employees.Emp_Role,
    yda_Employees.Emp_FirstName, yda_Employees.Emp_LastName,
    yda_ProgramsServices.Program_ID, yda_ProgramsServices.ProgramTitle,
    yda_ProgramsServices.District
    FROM yda_Employees INNER JOIN yda_ProgramsServices ON yda_Employees.Emp_ID =
    yda_ProgramsServices.ProgramContact
    GROUP BY yda_Employees.Emp_ID, yda_Employees.Emp_Role,
    yda_Employees.Emp_FirstName, yda_Employees.Emp_LastName,
    yda_ProgramsServices.Program_ID, yda_ProgramsServices.ProgramTitle,
    yda_ProgramsServices.District
    ORDER BY yda_Employees.Emp_ID ASC, yda_ProgramsServices.District DESC
    </cfquery>


    <!-- set the admin login level for each employee --->

    <cfif isDefined("rsGetEmployeeList.Emp_Role") AND
    rsGetEmployeeList.Emp_Role EQ 1>
    <cfset EmployeeRole ="Administrator">
    <cfelseif isDefined("rsGetEmployeeList.Emp_Role") AND
    rsGetEmployeeList.Emp_Role EQ 2>
    <cfset EmployeeRole ="Data Input Only">
    <cfelse>
    <cfset EmployeeRole ="No Level Assigned">
    </cfif>



    <!--- Set the School District for each program --->
    <cfif isDefined("rsGetEmployeeList.District") AND
    rsGetEmployeeList.District EQ 1>
    <cfset SchoolDistrict = "Hrbrflds/Elwd">
    <cfelseif isDefined("rsGetEmployeeList.District") AND
    rsGetEmployeeList.District EQ 2>
    <cfset SchoolDistrict = "Npt./E. Npt.">
    <cfelse>
    <cfif isDefined("rsGetEmployeeList.District") AND
    rsGetEmployeeList.District EQ 3>
    <cfset SchoolDistrict = "Both">
    </cfif>
    </cfif>


    Here is the Query Output:

    <table width="100%" border="0" cellpadding="3" cellspacing="10" id="border">
    <tr>
    <td colspan="3"><h5>Employees</h5></td>
    </tr>
    <cfoutput query="rsGetEmployeeList" Group="Emp_ID">
    <tr>
    <td>
    <p>
    #rsGetEmployeeList.Emp_FirstName#
    #rsGetEmployeeList.Emp_LastName#<br>
    Admin Level: #EmployeeRole# - #rsGetEmployeeList.Emp_Role#<br>

    *** I output the role to see if it was being read correctly and it is

    Programs Head:<br>
    <cfoutput>#rsGetEmployeeList.ProgramTitle# - #SchoolDistrict#
    (#rsGetEmployeeList.District#)<br></cfoutput> </td>

    ***The number in the parens is the district that should be converted to the
    "ShcoolDistrict" variable.***


    <td><a
    href="InsertEmployee.cfm?EmployeeID=#rsGetEmployee List.Emp_ID#">Edit</a></td>
    <td><a
    href="DeleteEmployee.cfm?EmployeeID=#rsGetEmployee List.Emp_ID#">Delete</a></td>
    </tr>
    </cfoutput>
    </table>


    Here is the actual HTML that is viewed in the browser. See the numbers are
    correct, but the variable ShcoolDistrict is being read as "both" no matter
    what the corresponding number is. And, the Admin Level is being set to
    Administrator even for someone with the level of "2".
    Rod Miller
    Admin Level : Administrator - 1
    Programs Head:
    Individual Counseling - Both (3)

    Max Burns
    Admin Level : Administrator - 2 **** Should be set to Data Input Only
    Programs Head:
    NMS YDA Afterschool - Both (2)


    Shannon Killeen
    Admin Level : Administrator - *** Should show No Level Assigned
    Programs Head:
    International Cooking - Both (3)
    ENMS YDA After School - Both (2) *** Should show Npt./E. Npt.
    Northport Youth Council - Both (2)
    Grandfriends - Both (2)
    Girls Only - Both (2)
    Northport High School Drop-In - Both (1) *** Should be set to Hrbrflds/Elwd
    Northport Middle School Drop In - Both (1)


    KimMazz Guest

  2. Similar Questions and Discussions

    1. CFIF help
      I have an HTML that has a list of names pulled from a Database. In my HTML table my headers are Read, Write, Release, View For each employee that...
    2. CFIF Big Problem
      hi All, ok I?ma beginnner with CF. Maybe this sounds ridiculous but by me the" if" condition of Coldfusion don?t work. System: XP , Editor:...
    3. Use of CFIF with in a CFSWITCH
      Is it possible to use a cfif statement with in a cfswitch statement. below is an example: <cfswitch expression="#var1#"> <cfcase>some...
    4. problem with cfif
      Hello all as you the codes I've written you will notice that all of the <cfif> and </cfif> are pairs but I have been recieved this error: Context...
    5. cfif being ignored
      I wanted this to only execute if FORM.rp_image does not = defaultImg.gif but it seems to always run. I thought the syntax was okay but maybe not. ...
  3. #2

    Default Re: CFIF is being ignored

    You need to get all those cfifs down inside the <cfoutput query=> loop.
    Standalone at the top as you have them now, CF does them only once using only
    the first row.

    Also, what was the intent of the IsDefined? A better way to do that is <cfif
    rsGetEmployeeList.RecordCount GT 0>. If the query returned any rows at all,
    all columns are IsDefined otherwise all columns are NOT IsDefined. However, if
    everything is down in the <cfoutput loop you don't even need that. If there
    are no rows returned it's bypassed, so you might want to precede the <cfouput>
    with a <cfif rsGetEmployeeList.RecordCount EQ 0><p>No Employees Found<cfelse>

    JMGibson3 Guest

  4. #3

    Default Re: CFIF is being ignored

    JMGibson3

    Thanks for the help. I thought all the processing code had to be at the top
    of a page. When I moved it in to the query output then it worked.

    And, as for the intent of the IsDefined. Is that in reading the WACK book I
    thought it said to always check to make sure a variable exists. So, I
    thought it correct to check to make sure the value was defined before
    setting the variable.

    I can't check for a record count, because there will always be employees,
    but each employee may or may not have a district or login set for them.

    Kim

    "JMGibson3" <webforumsuser@macromedia.com> wrote in message
    news:dvmu1f$oou$1@forums.macromedia.com...
    > You need to get all those cfifs down inside the <cfoutput query=> loop.
    > Standalone at the top as you have them now, CF does them only once using
    > only
    > the first row.
    >
    > Also, what was the intent of the IsDefined? A better way to do that is
    > <cfif
    > rsGetEmployeeList.RecordCount GT 0>. If the query returned any rows at
    > all,
    > all columns are IsDefined otherwise all columns are NOT IsDefined.
    > However, if
    > everything is down in the <cfoutput loop you don't even need that. If
    > there
    > are no rows returned it's bypassed, so you might want to precede the
    > <cfouput>
    > with a <cfif rsGetEmployeeList.RecordCount EQ 0><p>No Employees
    > Found<cfelse>
    >

    KimMazz Guest

  5. #4

    Default Re: CFIF is being ignored

    You don't really have to check if a variable exists if you KNOW it exists. Of
    course if you only thought it exists your users may be looking at error pages
    every once in awhile. That's probably the reason behind the WACK suggestion,
    but it sure makes for a lot more coding. I never do, unless there's a chance
    it doesn't exist: timed out session variables, Form variables, pages running
    with or without URL parms, etc.

    JMGibson3 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139