Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop records into a table 1

Status
Not open for further replies.

baggen

Technical User
Aug 18, 2007
6
SE
Hi!

In a script I pick up the three latest articles to be shown on a newspage:
[blue]
query = "select top 3 newsid,newsname,catid,newsdateadded,newsdescription,newsdoc1name from NMNewstbl where activated = true and newsexpiry > #"& date() &"# order by newsdateadded desc"
set rs = dataconn.Execute(query)[/blue]

These articles is executed by the following code:
[blue]
if not rs.eof then
Response.Write "<br><TABLE WIDTH=30% align=center valign=top style="&tablestyle&" BORDER=0 CELLSPACING=0 CELLPADDING=4>"
Response.Write "<tr><td colspan=2 width=100% bgcolor="& headerbgcolor&" valign=top><FONT face="&fontface&" size="& headerfontsize&" color="& headerfontcolor&">Rubriker</font></td></tr>"
do until rs.eof
Response.Write "<tr>"
Response.Write "<td width=80% valign=top><FONT face="&fontface&" size="&fontsize&" color="&fontcolor&"><i>"&rs(1)&" "&rs(3)&"</i><br>"&rs(4)&"<br><a href="""&weburl&"?dtype=4&catid="&rs(2)&"&recid="&rs(0)&""">...Läs mer</a></font><br><br></td></tr>"
rs.movenext
loop
Response.Write "</table>")[/blue]

This works very well, but now I want to show the three articles like a L in the table, like this:
[red]<table><tr><td>First article</td><tr>
<tr><td>Second article</td><td>Third article</td></tr>
</table>[/red]

Is there anyone who could give me a hint...?

Regards,
/Paul
 
The simlpest solution would be to create a counter and increment it inside the loop. Initialize the counter at 1 and you could generate the necessary content based on that count:
Code:
Dim recCtr : recCtr = 1
do until rs.eof 
   If recCtr = 1 Then
      'start the first cell
      Response.Write "<tr><td>"
   ElseIf  recCtr = 2 Then
      'end the first cell/row and start second
      Response.Write "</td></tr><tr><td>"
   ElseIf recCtr = 3 Then
      'end the second article, start third
      Response.Write "</td><td>"
   End If
   
   ...
   ...

   recCtr = recCtr + 1
Loop

Another, more complex method would be to use stop using the table for layout and switch to div's with CSS. You would probably still want the counter but then you would just use it to output a differant classname for each item, using the CSS to define the layouts for those three articles.

-T

Best MS KB Ever:
 
Thanks a lot, Tarwn! It works like a charm!

And about CSS: I'm working on it. I'm doing a simple website for a friend, and on this site I'm only using pure CSS.
Once again: Thank you!

Regards,
Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top