Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Display Recordset Data in columns across page

Posted on 2004-10-05
3
Medium Priority
?
502 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 800 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 200 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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/…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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