Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 3rd, 2004, 09:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Please replace the first three lines in my previous post with this. <TR> tag was not balanced in my earlier post. I have removed the <TR> from the 3rd line.

Code:
 Response.write "<table border=1>"
 Response.write "<tr><td><b>Event Name</b></td>"
 Response.write "<td><b>BoatName</b></td>"


Cheers!

_________________________
-Vijay G
Strive for Perfection
 
Old June 3rd, 2004, 11:35 AM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 166
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi again, this almost works the way I want it, the table works fine now but the Event dosen't work right. It shows like this

Event(1)

Event(2)

Headings
Record for event(1)
Record #2 for event(1)
Record for event(2)
Record #2 for event(2)

I need the Record for event(1) to show under the first event title

This is starting to hurt my head, :)

I can't loop through the whole record because it makes a new table with new headings but then there in the right spot.

This is what I need to show(somehow)
<---Event Title---->
If .Fields("Event").Value <> OldEventName Then
  OldEventName = .Fields("Event").Value
 Response.Write("<h2>" & .Fields("Event").Value & "</h2>")
End If

Do While Not .EOF

<----Table with headings--->
(I need this to be made once per event)

    Response.write "<table border=1>"
 Response.write "<td><b>BoatName</b></td>"
 Response.write "<td><b>Sail #</b></td>"
 Response.write "<td><b>Type</b></td>"
 Response.write "<td><b>Date</b></td>"
 Response.write "<td><b>Position</b></td>"
 Response.write "<td><b>Time</b></td></tr>"

<---Record set corresponding to the proper event title---->

Response.write "<tr><td>"
Response.Write(.Fields("BoatName").Value & "</td><td>" & _
.Fields("SailNum").Value & "</td><td>" & _
.Fields("Type").Value & "</td><td>" & _
.Fields("RaceDate").Value & "</td><td>" & _
.Fields("Position").Value & "</td><td>" & _
.Fields("RaceTime").Value & "</td></tr>")
.MoveNext()
   Loop
Response.write "</table>"

I don't even know what I am talking about anymore


-----------------------------------------------------------
"Don't follow someone who's not going anywhere" John Mason
 
Old June 3rd, 2004, 04:16 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi morpheus,

If I understand you correctly, you should simply move the code that writes out the table heading to the part that also writes the <h2>. In my initial example, I used the <h2> tag to indicate the "parent" element, the author. Each h2 / author was followed by a list of books. In your case, you should do that with the events like this:
Code:
Response.Write("<h2>" & .Fields("Event").Value & "</h2>")

' <----Table with headings--->
(I need this to be made once per event)

 Response.write "<table border=1>"
 Response.write "<td><b>BoatName</b></td>"
 Response.write "<td><b>Sail #</b></td>"
 Response.write "<td><b>Type</b></td>"
 Response.write "<td><b>Date</b></td>"
 Response.write "<td><b>Position</b></td>"
 Response.write "<td><b>Time</b></td></tr>" 

End If

Do While Not .EOF
...
Hope this helps.

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old June 4th, 2004, 07:19 AM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 166
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You guys are really great and it's almost there. With your advice Imar the tables and headings are working fine, but they are not sorting correctly under the right event(author) it is showing like this

Author(1)

Author(2)
Headings
Author(1) Book(1)
Author(1) Book(2)

Headings
Author(2) Book(1)
Author(2) Book(2)

  With rsEvents
    Dim OldEventName
    Dim OldYachtClub

    If Not .EOF then
      ' Loop through entire recordset with duplicate Events data and Placing

Do While Not .EOF

If .Fields("Event").Value <> OldEventName Then
  OldEventName = .Fields("Event").Value
 Response.Write("<h2>" & .Fields("Event").Value & "</h2>")

    Response.write "<table border=1>"
 Response.write "<td><b>BoatName</b></td>"
 Response.write "<td><b>Sail #</b></td>"
 Response.write "<td><b>Type</b></td>"
 Response.write "<td><b>Date</b></td>"
 Response.write "<td><b>Position</b></td>"
 Response.write "<td><b>Time</b></td></tr>"

End If

' Now display the Placing stuff

Response.write "<tr><td>"
Response.Write(.Fields("BoatName").Value & "</td><td>" & _
.Fields("SailNum").Value & "</td><td>" & _
.Fields("Type").Value & "</td><td>" & _
.Fields("RaceDate").Value & "</td><td>" & _
.Fields("Position").Value & "</td><td>" & _
.Fields("RaceTime").Value & "</td></tr>")
.MoveNext()
   Loop
Response.write "</table>"


     End If
    .Close
    Set rsEvents = Nothing
  End With

I moved the table headings inside the End if for the event's and that worked.

Thanks

-----------------------------------------------------------
"Don't follow someone who's not going anywhere" John Mason
 
Old June 4th, 2004, 07:29 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Code:
If .Fields("Event").Value <> OldEventName Then
  OldEventName = .Fields("Event").Value
 Response.Write("<h2>" & .Fields("Event").Value & "</h2>")

 Response.write "<table border=1>"
 Response.write "<TR><td><b>BoatName</b></td>"
 Response.write "<td><b>Sail #</b></td>"
 Response.write "<td><b>Type</b></td>"
 Response.write "<td><b>Date</b></td>"
 Response.write "<td><b>Position</b></td>"
 Response.write "<td><b>Time</b></td></tr>"


In the above code, I dont see you starting a <TR> tag.

Is that the culprit, can you check?
Cheers!

_________________________
-Vijay G
Strive for Perfection
 
Old June 4th, 2004, 07:34 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I think this is caused by the way the browser displays your table. I think that you're not properly closing the </table> tag.

I think you need to take a look at the source of the page in the browser. I wouldn't be surprised if the stuff comes up in the correct order in the HTML, but since the <h2> tags are placed outside the table, they are displayed on the page before the table.

If you look at the source, you can see the </table> is closed only after the very last loop. However, you need to close the table after each "author" / event. The best place to do is probably after the call to MoveNext. Something like this should work:

.MoveNext()
' Recordset has advanced 1 record, and is pointing
' to EOF or the next record
  If .EOF Then
    ' You displayed the last record, close the table
    Response.write "</table>"
  Else
    ' There are more records. Let's see if the next
    ' Event matches the current event
    If .Fields("Event").Value <> OldEventName Then
      ' No, next event is differnet, so close current table
      Response.write "</table>"
    End If
  End If
Loop
<s>Response.write "</table>"</s>

I think this should do the trick, although I haven't tested it. If everything works out as planned, you end up with a complete table for each event, preceded by a <h2> with the Event name, or whatever it is you're displaying.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old June 4th, 2004, 08:35 AM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 166
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That's it Imar thanks a lot for your help :)
If someone wants me to post the finished code just let me know

Thanks again

-----------------------------------------------------------
"Don't follow someone who's not going anywhere" John Mason
 
Old June 4th, 2004, 08:42 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Glad it's working.

Please post the final code; I am sure someone will benefit from it in the future. You might want to limit the code to just the part that gets the data and displays it, without posting the entire HTML page.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old June 4th, 2004, 08:53 AM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 166
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I left out the sql and connection code, here is the code that will create a Title and A table with headings for every record corresponding to that Title under it. I have also removed my info and made the code more generic

<%
    If Not .EOF then
      ' Loop through entire recordset with duplicate Title data and Table Body

Do While Not .EOF

If .Fields("Title").Value <> OldTitleName Then
  OldTitletName = .Fields("Title").Value
 Response.Write("<h2>" & .Fields("Title").Value & "</h2>")

    Response.write "<table border=1>"
 Response.write "<tr><td><b>Heading1</b></td>"
 Response.write "<td><b>Headin2</b></td>"
 Response.write "<td><b>Headin3</b></td>"
 Response.write "<td><b>Headin4</b></td>"
 Response.write "<td><b>Headin5</b></td>"
 Response.write "<td><b>Headin6</b></td></tr>"

End If

' Now display the Table Body stuff

Response.write "<tr><td>"
Response.Write(.Fields("Column1").Value & "</td><td>" & _
.Fields("Column2").Value & "</td><td>" & _
.Fields("Column3").Value & "</td><td>" & _
.Fields("Column4").Value & "</td><td>" & _
.Fields("PColumn5").Value & "</td><td>" & _
.Fields("Column6").Value & "</td></tr>")

.MoveNext()
' Recordset has advanced 1 record, and is pointing
' to EOF or the next record
  If .EOF Then
    ' You displayed the last record, close the table
    Response.write "</table>"
  Else
    ' There are more records. Let's see if the next
    ' Title matches the current Title
    If .Fields("Title").Value <> OldTitleName Then
      ' No, next event is differnet, so close current table
      Response.write "</table>"
    End If
  End If
Loop
%>

-----------------------------------------------------------
"Don't follow someone who's not going anywhere" John Mason





Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop through 17 tables in RecordSet object didimichael C# 1 July 18th, 2008 06:53 AM
loop through tables inside .mdb file using VB.NET remya1000 General .NET 3 September 24th, 2007 12:45 PM
creating tables within tables in access??? carswelljr Access 3 August 23rd, 2006 01:21 PM
Help with for-each loop athanatos XSLT 0 April 10th, 2006 07:20 PM
nested while loop doesn't loop hosefo81 PHP Databases 5 November 12th, 2003 08:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.