If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > How to Display 2 different tables on one page

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-28-03, 10:59
Bigced_21 Bigced_21 is offline
Registered User
 
Join Date: Dec 2002
Location: KY
Posts: 54
Exclamation How to Display 2 different tables on one page

I'm trying to get display two tables side by side, but with the code I'm using it's displaying a record from the first table every twentieth place with the information from the second table.

Here's the code: PLEASE HELP!!!!


' #### Get a list of all problems that aren't listed as COMPLETE
strSQL = "Select * from HBC_Alpha_Violation_CodeDef"
Set rs1 = ObjConn.Execute(strSQL)

' #### Display a list of all HBC_Alpha_Violation_CodeDef names and codes
strSQL = "Select * from HBC_Num_Violation_CodeDef"
Set rs2 = ObjConn.Execute(strSQL)

' Headings for the Violation Codes
Response.Write "<table> <CAPTION ALIGN=TOP><h3>Violation Table</h3></CAPTION><tr> <td width='75%'><h4>Alpha Violations</h4></td> <td width='35%'><h4>Num Code Violation</h4></td> </tr>"
Response.Write "<table><tr><td>ID</td><td>Name</td> <td>Code</td> <td width='18%'>Date Entered</td> <td width='4%'></td> <td width='3%'>ID</td> <td>Name</td> <td>Code</td> <td width='18%'>Date Entered</td></tr>"
Response.Write "<tr><td colspan='4'><table>"
i = 1

If i Mod 2 = 0 then
Response.Write "<tr bgcolor='white'>"
Else
Response.Write "<tr bgcolor='#D2DCF2'>"
End If

'Do while NOT rs1.EOF
'rs2.MoveFirst()

If rs1.EOF Then
Response.Write "<tr><td><a href='boiler_Violation_detail.asp?id=" & rs1("id") & "'>" & rs1("id") & "</a></td><td>&nbsp;&nbsp;" & rs1("Name") & "</td><td>" & rs1("Code") & "&nbsp;&nbsp;</td><td>" & rs1("Date_Created") & "<br>/td></table>"
Response.Write "</table>"
Response.Write "</td>"
Else
Response.Write "<tr><td><a href='boiler_Violation_detail.asp?id=" & rs1("id") & "'>" & rs1("id") & "</a></td><td>&nbsp;&nbsp;" & rs1("Name") & "</td><td>" & rs1("Code") & "&nbsp;&nbsp;</td><td>" & rs1("Date_Created") & "<br></td></table>"
Response.Write "</table>"
Response.Write "</td>"
End IF

Response.Write "<td>&nbsp;</td>"

Do while NOT rs2.EOF

If rs2.EOF Then
Response.Write "<td><a href='boiler_Violation_detail.asp?id=" & rs2("id") & "'>" & rs2("id") & "</a></td><td>&nbsp;&nbsp;" & rs2("Name") & "</td><td>" & rs2("Code") & "&nbsp;&nbsp;</td><td>" & rs2("Date_Created") & "</td></tr>"
Response.Write "</table>"
Response.Write "</td>"
Else
Response.Write "<td><a href='boiler_Violation_detail.asp?id=" & rs2("id") & "'>" & rs2("id") & "</a></td><td>&nbsp;&nbsp;" & rs2("Name") & "</td><td>" & rs2("Code") & "&nbsp;&nbsp;</td><td>" & rs2("Date_Created") & "</td></tr>"
Response.Write "</table>"
Response.Write "</td>"
End IF
'i = i + 1
rs2.MoveNext()
Loop
i = i + 1
'rs1.MoveNext()
'Loop
Response.Write "</table>"
Reply With Quote
  #2 (permalink)  
Old 02-28-03, 12:03
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: How to Display 2 different tables on one page

I can't tell you the code to write exactly, but the problem is that your current code has nested loops to get the data from the 2 tables:

Code:
Do while NOT rs1.EOF
  Do while NOT rs2.EOF
    rs2.MoveNext()
  Loop
  rs1.MoveNext()
Loop
So for every record returned by rs1 you are displaying all rows from rs2.

Instead you need to use a single loop and fetch 1 row from each until you run out of rows from both. I don't know the correct VB syntax for this, but something like:

Code:
DO while (NOT rs1.EOF OR NOT rs2.EOF)
  If NOT rs1.EOF then
    rs1.MoveNext
    (Display rs1 record)
  End If
  If NOT rs2.EOF then
    rs2.MoveNext
    (Display rs2 record)
  End If
Loop
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On