Solved

Display Recordset Data in columns across page

Posted on 2004-10-05
3
486 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

679 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