Looping with CSP:While
Our code currently faces two problems. First, the result set cursor initially points before the first row. This means that our Get methods will not return query data. To move the cursor to the first row we invoke the %ResultSetOpens in a new tab method Next one time. This brings us to our second problem. We want to display data from all rows of the result set not just the first. To accomplish this we need to create a loop that moves the cursor through each row in succession.
We solve both problems with a <csp:while> tag. This tag creates a loop that executes until the specified condition is false. In this case, the condition calls our Next method. Next moves the result set cursor and returns TRUE if there is a next row of data and FALSE if there is no next row of data.
<html> <body> <h2><font color="#0000FF">Today's Top Picks</font></h2> <table border=0> <csp:query name="FilmList" classname="Cinema.Film" queryname="TopFilms"> <csp:while condition="FilmList.Next()"> <tr> <td> <b>#(FilmList.Get("Title"))#</b><br> #(FilmList.Get("Description"))#<br> <b>Genre</b> #(FilmList.Get("CategoryName"))# <b>Length</b> #(FilmList.Get("Length"))# <b>Rating</b> #(FilmList.Get("Rating"))#<br> <br> </td> <td> </td> </tr> </csp:while> </table> </body> </html>