9.5.1 Special SQL Variables | |
Certain special variables are set by the <SQL> statement, in addition to any columns returned. Like most looping statements, $loop and $next are set.
The $loop variable is set at the start of every iteration of the <SQL> loop. It is the count of how many rows were returned so far, not including the current one. When the <SQL> loop ends, $loop is the number of rows returned. (Ie. up to MAX rows, but not including SKIP rows.)
The $next variable is also set every iteration, but as a row count from the start of the result set. It is set to the number of SKIP rows, plus $loop (returned rows), plus 1. Thus it is a useful variable for numbering the result set, as we do in our patent example, inside the <SQL> loop in the <search> function.=SKIP>. At the end of the loop, $next is the value to use for SKIP in a new loop to continue iterating results on the next page.
The $indexcount variable is set at the start of the first returned row, to an estimate of the total number of rows the query will return. The $rows.min and $rows.max variables are set similarly, but can be more accurate. These variables can be used to paginate results, as we'll see later.
Back: SQL Queries | Next: SQL Parameters |