Solved

Display Recordset Data in columns across page

Posted on 2004-10-05
3
468 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now