Solved

Display Recordset Data in columns across page

Posted on 2004-10-05
3
489 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Set time on Session (ASP) 14 38
window close link 7 66
Building JSON Results Table FROM DB 9 50
SQL to JSON 14 65
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
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/…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

710 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