Skip to main content
Participant
October 26, 2018
Question

Skipping the first tD while displaying the query result with a loop in a table

  • October 26, 2018
  • 2 replies
  • 779 views
I have a query getNamesandRoles that will display the result as such
    DISPLAYNAME   JOBROLE

    X                          X does someting

    Y                          Y does someting

    Z                          Z does someting

I want to display the result of this query in a table which is shown below, I can get to show the results with a loop or through explicitly calling the query as getNamesandRoles.displayName[1] and so on, but I can figure out how to loop thru the query in a way that would skip the first row where the ID (i.e. all the scope="row") and populate the data in the other two Td's dynamically so that it we have more users it creates those TD's related to the ID. Can i accomplish this ?

<table class="table table-bordered">

   <thead>

   <tr>

   <th scope="col">SomeroleID</th>

   <th scope="col">First</th>

   <th scope="col">Last</th>

  

   </tr>

   </thead>

   <tbody>

   <tr>

   <th scope="row">RoleFunction</th>

   <td>X</td>

   <td>X does someting</td>

  

   </tr>

   <tr>

   <th scope="row">RoleFunction1</th>

   <td>Y</td>

   <td>Y does someting </td>

  

   </tr>

   <tr>

   <th scope="row">RoleFunction</th>

   <td>z</td>

   <td>Z does someting  </td>

  

   </tr>

   </tbody>

   </table>

This topic has been closed for replies.

2 replies

Participant
October 29, 2018

Apologies about being unclear.

DATA from Query getNamesandRoles

DISPLAYNAME   JOBROLE

    X                          X does someting

    Y                          Y does someting

    Z                          Z does someting

I  want to populate the data in the format of the expected table with a loop so that the <td> for the headers are skipped but we can poplate displayname and Job role.

Thank you.

BKBK
Community Expert
Community Expert
October 29, 2018

Assuming the column names are roleFunction, displayName and jobRole, then you perhaps want something like

<table class="table table-bordered">

   <thead>

   <tr>

   <th scope="col">Role ID</th>

   <th scope="col">Name</th>

   <th scope="col">Role</th>

   </tr>

   </thead>

   <tbody>

   <cfoutput query="getNamesandRoles">

   <tr>

   <th scope="row">#getNamesandRoles.roleFunction#</th>

   <td>#getNamesandRoles.displayName#</td>

   <td>#getNamesandRoles.jobRole#</td>

   </tr>

   </cfoutput>

   </tbody>

</table>

WolfShade
Legend
October 30, 2018

Essentially the same thing I suggested.  OP indicated negatory.  (shrug)

V/r,

^ _ ^

WolfShade
Legend
October 26, 2018

I'm not sure I understand your question.  Is this what you're looking for?

<table class="table table-bordered">
  <thead>
  <tr>
  <th scope="col">SomeroleID</th>
  <th scope="col">First</th>
  <th scope="col">Last</th>
  </tr>
  </thead>

  <tbody>
<cfoutput query="queryName">
  <tr>
  <th scope="row">RoleFunction</th>
  <td>#queryName.colA#</td>
  <td>#queryName.colB#</td>
  </tr>
</cfoutput>
  </tbody>
</table>

V/r,

^ _ ^

Participant
October 27, 2018

No, that is not what i was looking for. I guess my question is about looping through the query and appending the values sequentially in dynamically created TD's for Some header, Some other header , and Something else entirely. Some way to populate a table but skipping the first TD.

<table class="table table-bordered">

   <thead>

   <tr>

   <th scope="col">SomeroleID</th>

   <th scope="col">First</th>

   <th scope="col">Last</th>

 

   </tr>

   </thead>

   <tbody>

   <tr>

   <th scope="row">Some header </th>

   <td>X</td>

   <td>X does someting</td>

 

   </tr>

   <tr>

   <th scope="row">Some other header </th>

   <td>Y</td>

   <td>Y does someting </td>

 

   </tr>

   <tr>

   <th scope="row">Something else entirely</th>

   <td>z</td>

   <td>Z does someting  </td>

 

   </tr>

   </tbody>

   </table>

BKBK
Community Expert
Community Expert
October 27, 2018

Hi Userfromcoloroado​, I have read your question a number of times. I still don't understand what you're asking.