How to loop over a query in ColdFusion

cfloop - loop over a query

cfloopquery.cfm


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>cfloop tag example: how to loop over a query in coldfusion</title>
</head>

<body>
<h2 style="color:Crimson">cfloop Tag Example: Query</h2>

<cfquery name="qEmployees" datasource="cfdocexamples">
 SELECT Emp_ID, FirstName, LastName FROM EMPLOYEES
</cfquery>

<cfoutput>
    <table cellpadding="0" cellspacing="0" style="color:White" border="1">
        <tr bgcolor="HotPink">
            <td><b>Emp_ID</b></td>
            <td><b>FirstName</b></td>
            <td><b>LastName</b></td>
        </tr>
        <cfloop query="qEmployees" startrow="1" endrow="10">
            <tr bgcolor=#IIF(qEmployees.CurrentRow mod 2 eq 0,DE("IndianRed"),DE("Red"))#>
                <td>#Emp_ID#</td>
                <td>#FirstName#</td>
                <td>#LastName#</td>
            </tr>
        </cfloop>
    </table>
</cfoutput>

</body>
</html>







More ColdFusion examples