0

I have this code that shows a table:

<cfloop  query="GetResults2">
<cfif GetResults2.dept_id eq aFieldValue>     
<table class="table1">
<th>Name</th><th>Positive Comment</th><th>Negative Comment</th>
<tr>
     <td nowrap="nowrap">#emp_namefirst# #Left(emp_namelast, 1)#  </td>
    <td>#Replace(commentpositive, emp_namefirst, "<B>" & emp_namefirst & "</B>")#</td>
    <td>#Replace(commentnegative, emp_namefirst, "<B>" & emp_namefirst & "</B>")#</td>
    </tr>


    </table>
</cfif>
</cfloop>

Right now it does get the correct results but its loopping every time and creating a new table for every row. How can I get it that it will only show one table? I have try moving the

<cfloop query="GetResults2"> inside the table but that doesnt solve the problem. Any suggestions on how to solve it?

user3591637
  • 499
  • 5
  • 20

2 Answers2

4

This will create one table with a row for each result in the query. The loop needs to be nested within the table and after the header rows.

<table class="table1">
  <th>Name</th>
  <th>Positive Comment</th>
  <th>Negative Comment</th>
  <cfloop  query="GetResults2">
    <cfif GetResults2.dept_id eq aFieldValue>     
      <tr>
        <td nowrap="nowrap">#emp_namefirst# #Left(emp_namelast, 1)#  </td>
        <td>#Replace(commentpositive, emp_namefirst, "<B>" & emp_namefirst & "</B>")#</td>
        <td>#Replace(commentnegative, emp_namefirst, "<B>" & emp_namefirst & "</B>")#</td>
      </tr>
    </cfif>
  </cfloop>    
</table>
Matt Busche
  • 14,216
  • 5
  • 36
  • 61
0

Move your loop to surround your tr tag.

<table>
    <th>...heading....</th>
    <cfloop query="GetResults2">
        <tr>
            <td>#GetResults2.emp_namefirst# #Left( GetResults2.emp_namelast, 1 )#</td>
        </tr>
    </cfloop>
</table>
Chris Tierney
  • 1,539
  • 1
  • 8
  • 16