Record count with PHP Phakt
How to add a record count beside data rows using PHP or phAKT. Somewhere after you declare your "recordset" add the following (the "_recordset" portion of the variable name means that you use the name of your own recordset):
1) $currentRow_recordset = $startRow_recordset + 1;
(Because initially the $startRow is "0", and this method enables the row numbers to expand on multiple pages as in DW code, on every successive "page" the $startRow variable is updated)
2) In your Repeat Region, where you want the row number to appear write within the PHP markers:
echo ($currentRow_recordset);
3) And finally, in the RepeatRegion ending code block, before $recordset->MoveNext(); add this line, so that you get an advance in the count —
$currentRow_recordset = $currentRow_recordset +1;
Now, a practical example: Let's walk through the $currentRow_recordset variable's "lifespan".
Let's assume that you defined 10 rows per page in your RepeatRegion and you have more than 10 rows in total. After adding the line of code below the recordset declaration in the code the $currentRow_recordset gets the value of "1" (0 + 1).
Now, when the page gets laid out, the number "1" appears on the first row where you inserted the second line of code, and as the repeat process starts to move to the next iteration the value of $currentRow_recordset is increased by adding one to itself so that on the next row number "2" appears, and so on until 10 rows have been displayed. By the tenth row the value of $currentRow_recordset is also 10.
When you click on the "Next page" link, the auto-generated code assigns variable $startRow_recordset the value of "10" (at the beginning of your recordset declaration), but when it reaches OUR first block of code this count is increased to "11" as the tenth row was already displayed.
So the first number on this page displayed is "11" as it logically should be...This process happens on every page of your repeat region and the row number is always right.
Hint #1! If you add our lines of code outside the boundaries of DW's commentary lines (// begin recordset and //end recordset) it won't upset DW and your recordset's name won't disappear from your ServerBehaviours and Bindings palettes!
Hint #2!For DW's built in PHP users there is a free extension at Tecnorama (www.tecnorama.org) which will do the coding for you -- unfortunately it won't be available in the SB-menu when you are using phAKT.
1) $currentRow_recordset = $startRow_recordset + 1;
(Because initially the $startRow is "0", and this method enables the row numbers to expand on multiple pages as in DW code, on every successive "page" the $startRow variable is updated)
2) In your Repeat Region, where you want the row number to appear write within the PHP markers:
echo ($currentRow_recordset);
3) And finally, in the RepeatRegion ending code block, before $recordset->MoveNext(); add this line, so that you get an advance in the count —
$currentRow_recordset = $currentRow_recordset +1;
Now, a practical example: Let's walk through the $currentRow_recordset variable's "lifespan".
Let's assume that you defined 10 rows per page in your RepeatRegion and you have more than 10 rows in total. After adding the line of code below the recordset declaration in the code the $currentRow_recordset gets the value of "1" (0 + 1).
Now, when the page gets laid out, the number "1" appears on the first row where you inserted the second line of code, and as the repeat process starts to move to the next iteration the value of $currentRow_recordset is increased by adding one to itself so that on the next row number "2" appears, and so on until 10 rows have been displayed. By the tenth row the value of $currentRow_recordset is also 10.
When you click on the "Next page" link, the auto-generated code assigns variable $startRow_recordset the value of "10" (at the beginning of your recordset declaration), but when it reaches OUR first block of code this count is increased to "11" as the tenth row was already displayed.
So the first number on this page displayed is "11" as it logically should be...This process happens on every page of your repeat region and the row number is always right.
Hint #1! If you add our lines of code outside the boundaries of DW's commentary lines (// begin recordset and //end recordset) it won't upset DW and your recordset's name won't disappear from your ServerBehaviours and Bindings palettes!
Hint #2!For DW's built in PHP users there is a free extension at Tecnorama (www.tecnorama.org) which will do the coding for you -- unfortunately it won't be available in the SB-menu when you are using phAKT.
Comments
Be the first to write a comment
You must me logged in to write a comment.