Solved

Display Recordset Data in columns across page

Posted on 2004-10-05
3
477 Views
Last Modified: 2012-05-05
Hi,

got the following code, need to display the data across the page in 4 columns with width "100%" rather than the present code which grows downwards row by row.

<%
      'Open database get categories.
        set rs=openrs("SELECT * FROM boatclasses WHERE marineid=" & id & "ORDER BY id")
        if not rs.eof then
          rs.movefirst
            while not rs.eof
            boatclassname=rs("name")
            boatclassid=rs("id")
            boatclassimage=rs("largeimage")
        %>
                          <table cellpadding="0" cellspacing="0" border="0">
                            <tr>
                              <td><img src="../images/<%=boatclassimage%>" width="60"></td>
                            </tr>
                            <tr>
                              <td>
                                <div align="center"><a href="boatclass.asp?id=<%=boatclassid%>"><%=boatclassname %></a></div>
                              </td>
                            </tr>
                          </table>
                          <%
          rs.movenext
          wend
      end if
      rs.close
      set rs=nothing
      %>
0
Comment
Question by:fgict
  • 2
3 Comments
 
LVL 15

Expert Comment

by:gladxml
ID: 12226016
you can try this code...

<%
      'Open database get categories.
       set rs=openrs("SELECT * FROM boatclasses WHERE marineid=" & id & "ORDER BY id")
       if not rs.eof then
         rs.movefirst
          loopcount = 0%>
<table cellpadding="0" cellspacing="0" border="0"  width="100%" >
              <%while not rs.eof
          boatclassname=rs("name")
          boatclassid=rs("id")
          boatclassimage=rs("largeimage")
       loopcount = loopcount + 1
         if loopcount = 1 then%>
         <tr><td>
         <%else%>
         <td>
         <%end if%>
        
                          <table cellpadding="0" cellspacing="0" border="0">
                            <tr>
                              <td><img src="../images/<%=boatclassimage%>" width="60"></td>
                            </tr>
                            <tr>
                              <td>
                                <div align="center"><a href="boatclass.asp?id=<%=boatclassid%>"><%=boatclassname %></a></div>
                              </td>
                            </tr>
                          </table>
                          <%
            if loopcount = 4 then%>
            </td></tr>
            <%else%>
            </td>
            <%
            end if                   
         rs.movenext
         wend
      end if
      rs.close
      set rs=nothing
      %>
</table>

0
 
LVL 15

Assisted Solution

by:gladxml
gladxml earned 200 total points
ID: 12226088
Use thsi instead... there is some minor error on my first post...


<%
      'Open database get categories.
       set rs=openrs("SELECT * FROM boatclasses WHERE marineid=" & id & "ORDER BY id")
       if not rs.eof then
         rs.movefirst
          loopcount = 0%>
<table cellpadding="0" cellspacing="0" border="0"  width="100%" >
              <%while not rs.eof
          boatclassname=rs("name")
          boatclassid=rs("id")
          boatclassimage=rs("largeimage")
       loopcount = loopcount + 1
         if loopcount = 1 then%>
         <tr><td>
         <%else%>
         <td>
         <%end if%>
        
                          <table cellpadding="0" cellspacing="0" border="0">
                            <tr>
                              <td><img src="../images/<%=boatclassimage%>" width="60"></td>
                            </tr>
                            <tr>
                              <td>
                                <div align="center"><a href="boatclass.asp?id=<%=boatclassid%>"><%=boatclassname %></a></div>
                              </td>
                            </tr>
                          </table>
                          <%
            if loopcount = 4 then
            loopcount = 0
            %>
            </td></tr>
            <%else%>
            </td>
            <%
            end if                   
         rs.movenext
         wend
      end if
      rs.close
      set rs=nothing
      %>
<%if (loopcount < 4) AND (loopcount > 0) then
for i = loopcount to 4
%>
                                    <td>       
                          <table cellpadding="0" cellspacing="0" border="0">
                            <tr>
                              <td></td>
                            </tr>
                            <tr>
                              <td>
                                <div align="center></div>
                              </td>
                            </tr>
                          </table>
                                      </td>
<%next%>                                      
</tr>                                      
</table>
0
 
LVL 3

Accepted Solution

by:
topazg earned 50 total points
ID: 12226280
That would work - I would do this as follows:

<%
'Open database get categories.
set rs=openrs("SELECT * FROM boatclasses WHERE marineid=" & id & "ORDER BY id")
if not rs.eof then
    rs.movefirst
%>
<!-- New table to hold all four columns with 100% width, creating the first row also -->
<table width="100%">
<tr>
<%
count = 0
while not rs.eof
if count < 4 then
    boatclassname=rs("name")
    boatclassid=rs("id")
    boatclassimage=rs("largeimage")
%>
<!-- Each column is 25% of the whole table, keeping them evenly sized -->
<td width="25%">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td><img src="../images/<%=boatclassimage%>" width="60"></td>
</tr>
<tr>
<td>
<div align="center"><a href="boatclass.asp?id=<%=boatclassid%>"><%=boatclassname %></a></div>
</td>
</tr>
</table>
</td>
<%
        count = count + 1
    end if
' If four cells have been populated for the row, reset the counter, close the row and start a new one
    if count = 4 then
        count = 0
        Response.write("</tr>" & chr(10) & "<tr>")
    end if
    rs.movenext
    wend
%>
<!-- at end of data close the row and then the table -->
</tr></table>
<%
end if
rs.close
set rs=nothing
%>
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SMS AddAttachment Protocol Error Classic ASP 10 42
HTML in email body has extra  tick marks 3 76
ASP Focus problem 3 61
JQuery to parse xml string and get element by id 4 34
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question