JohnDoe4136
JohnDoe4136

Reputation: 539

Count and Display number of records - ASP

i'm trying to create running counter for SQL data in asp. For example,

Name

James

John

Mary

Instead I like to have it in

Name

  1. James
  2. John
  3. Mary

The code I have is this...

    <%
    if registerRS.recordcount > 0 Then
    registerRS.movefirst
    End If
    %>

<table border=1 cellpadding=0 cellspacing=0>
      <tr>    
        <th width="50" font class="tblhdr" style="width:400px;">Name</th>
<%
Do while not registerRS.eof  

%>
       <th width="50" font class="pgcont" valing=left style="width:400px;">     <%=registerRS.Fields("name")%></th>

<%
   registerRS.movenext
loop
registerRS.close
set registerRS=nothing 
End sub
%>

Upvotes: 0

Views: 395

Answers (2)

ipr101
ipr101

Reputation: 24236

If you're committed to using your table the following (untested) code should work, as Curt points out you could also use an <ol> and avoid making changes to your code logic -

    <%
    Dim counter
    counter = 1
    if registerRS.recordcount > 0 Then
    registerRS.movefirst
    End If
    %>

<table border=1 cellpadding=0 cellspacing=0>
      <tr>    
        <th width="50" font class="tblhdr" style="width:400px;">Name</th>
<%
Do while not registerRS.eof  

%>
       <th width="50" font class="pgcont" valing=left style="width:400px;"><%=counter%>.&nbsp;<%=registerRS.Fields("name")%></th>

<%
   registerRS.movenext
   counter = counter + 1
loop
registerRS.close
set registerRS=nothing 
End sub
%>

Upvotes: 1

Curtis
Curtis

Reputation: 103358

Rather than using a table, and calculating the position of each item, you could use an ordered list (<ol>):

http://www.w3schools.com/html/html_lists.asp

This will automatically display a number next to each list item.

Upvotes: 4

Related Questions