Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    192
    Thanks
    143
    Thanked 0 Times in 0 Posts

    adding a counter

    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


    Code:
    	//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

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,253
    Thanks
    203
    Thanked 2,557 Times in 2,535 Posts
    A counter to count what?

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    Regular Coder
    Join Date
    Sep 2011
    Posts
    192
    Thanks
    143
    Thanked 0 Times in 0 Posts
    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

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,206
    Thanks
    80
    Thanked 4,566 Times in 4,530 Posts
    Code:
    //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 ...
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    jason_kelly (05-23-2012)

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,206
    Thanks
    80
    Thanked 4,566 Times in 4,530 Posts
    Though why you are doing this with client-side code instead of with, say, ASP is beyond me.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Regular Coder
    Join Date
    Sep 2011
    Posts
    192
    Thanks
    143
    Thanked 0 Times in 0 Posts
    Thanks Old Pendant!

    Works like a charm


  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,206
    Thanks
    80
    Thanked 4,566 Times in 4,530 Posts
    WHOOPS! AN ERROR IN THAT!!

    WRONG:
    Code:
        str_html += '<tr><td>' + counter + '</tr>\n';
    RIGHT:
    Code:
        str_html += '<tr><td>' + counter + '</td>\n';
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •