...

View Full Version : adding a counter



jason_kelly
05-23-2012, 06:13 PM
Hi There,

I need your help.

When I am compiling an HTML report from a recordset, it would be nice to add a counter at the start of each line item/entry on the <td></td>

How could I modify the code below to incorporate a counter? What the existing code does is populate 16 columns of data. Id like to have it like the following though when it is executed:

1. valueA valueB valueC valueD valueE
2. valueA valueB valueC valueD valueE
3. valueA valueB valueC valueD valueE
4. valueA valueB valueC valueD valueE
5. valueA valueB valueC valueD valueE
ect.

as oppose to:

valueA valueB valueC valueD valueE
valueA valueB valueC valueD valueE
valueA valueB valueC valueD valueE
valueA valueB valueC valueD valueE
valueA valueB valueC valueD valueE




//FETCH RECORDSET FIELD VALUES
rs.MoveFirst
while (!rs.eof) {
str_html += '<tr>\n'
for (var r = 0; r < rs.fields.count; ++r) {
str_html += '<td style="height:10px;white-space:nowrap;overflow:hidden;">'+rs.fields(r).value+'</td>\n'
}//end of for
str_html += '</tr>\n'
rs.MoveNext
}//end of while

Philip M
05-23-2012, 06:46 PM
A counter to count what?

jason_kelly
05-23-2012, 07:08 PM
Hi Phil,

A counter to count the line item number

ie.

1. valueA valueB valueC valueD
2. valueA valueB valueC valueD
3. valueA valueB valueC valueD
4. valueA valueB valueC valueD
5. valueA valueB valueC valueD

Old Pedant
05-23-2012, 07:11 PM
//FETCH RECORDSET FIELD VALUES
rs.MoveFirst; // almost NEVER needed!
var counter = 0;
while (!rs.eof) {
++counter
str_html += '<tr><td>' + counter + '</tr>\n';
... rest same ...

Old Pedant
05-23-2012, 07:12 PM
Though why you are doing this with client-side code instead of with, say, ASP is beyond me.

jason_kelly
05-23-2012, 07:27 PM
Thanks Old Pendant!

Works like a charm

:)

Old Pedant
05-23-2012, 07:40 PM
WHOOPS! AN ERROR IN THAT!!

WRONG:


str_html += '<tr><td>' + counter + '</tr>\n';


RIGHT:


str_html += '<tr><td>' + counter + '</td>\n';



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum