SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Feb 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ASP Table Row Loops

    Hi there,

    I cant seem to work something out.
    I am selecting records from an mdb database, which i manage easy, but what I want to happen is after every second record I need to add <tr> tags so a new row in the table occurs.

    So for eample x number of records in the table.

    the end code should like this.

    HTML Code:
    <table border="0">
    
    <tr>
    <td>Record 1</td>
    <td>Record 2</td>
    </tr>
    
    <tr>
    <td>Record 3</td>
    <td>Record 4</td>
    </tr>
    
    </table>
    Any thoughts anyone.

    Thanks

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,608
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Just set a counter before the loop, then use Mod 2 to determine when to use TR. Pseudo-code ...
    Code:
    ctr = 1 'Means first time in loop we get a TR tag
    Do while not RS.EOF
      ctr = ctr + 1
      If ctr Mod 2 = 0 Then 'Mod 2 means divide by 2 and look at the remainder
        ctr = 0
        Response.Write "<tr>" & vbNewLine
      End if
      Response.write "<td>" & RS("fieldname") & "</td>" & vbNewLine
      If ctr = 1 Then Response.Write "</tr>" & vbNewLine 'Do the /TR tag
      RS.movenext
    Loop
    'Now we need to close out the table properly
    If ctr = 0 Then
      Response.write "<td>&nbsp</td>" & vbNewLine
      Response.write "</tr>" & vbNewLine
    End if
    Have fun!
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,608
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I am puzzled by your post. What relevance does it have to this thread?
    Ian Anderson
    www.siteguru.co.uk

  4. #4
    SitePoint Member
    Join Date
    Feb 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks siteguru your original post worked fine.

  5. #5
    SitePoint Member
    Join Date
    Feb 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Jack4321 this has no relevance to what im asking.

    Think your in the wrong place mate.


Tags for this Thread

Bookmarks

Posting Permissions

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