Web Analytics Made Easy -
StatCounter Problem with Rows and Columns - CodingForum

Announcement

Collapse
No announcement yet.

Problem with Rows and Columns

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with Rows and Columns

    Hi,
    I'm trying to get my products to display in three columns.
    I have 24 products in a couple of catagories which display fine.

    Question: how do i get other catagories with quantities of less or more than 24 items to display with out an error - i need the table to expand or contact according to number of items.

    Thanks in advance.


    <%
    Set prodRS = Server.CreateObject( "ADODB.Recordset" )
    prodRS.ActiveConnection = Con
    DIM prodcat
    sqlString = "SELECT product_id, product_picture, product_name " &_
    "FROM Products WHERE product_category='" & cat & "' " &_
    "AND product_status=1 " &_
    "ORDER BY product_id "

    prodRS.Open sqlString
    %>

    <table border="0" width="100%">

    <%
    FOR row = 1 TO 8
    %>
    <tr>
    <%
    FOR col = 1 TO 3
    %>
    <td valign="top"><%response.write prodRS( "product_name" )%></b>
    <%prodcat = prodRS( "product_name" )%>
    <% IF prodRS( "product_picture" ) <> "?????" THEN %>
    <a href="product.asp?pid=<%=prodRS( "product_id" )%>"><IMG SRC="../thumbs/<%=prodRS( "product_picture" )%>s.jpg" border="1" align="center"></a></font>
    <% END IF %>

    <%
    prodRS.MoveNext
    NEXT
    %>

    </tr>
    <%
    NEXT
    %>

    </table>

  • #2
    Try this:
    Code:
    <%
    dim col, colCount
    colCount = 3 'number of columns to display, change as desired
    col = 1
    %>
    <table border="0" width="100%">
    <%
      while not prodRS.BOF and not prodRS.EOF
         if col = 1 then response.write "<tr>" 'new row
         if col <= colCount then
       %>
         <td valign="top">
           <b><%response.write prodRS( "product_name" )%></b>
           <% if prodRS( "product_picture" ) <> "?????" THEN %>
             <a href="product.asp?pid=<%=prodRS( "product_id" )%>"><IMG SRC="../thumbs/<%=prodRS( "product_picture" )%>s.jpg" border="1" align="center"></a>
           <% end if
              col = col + 1 'increment cell
              prodRS.MoveNext
              if prodRS.EOF and col <= colCount then
                  for i = col to colCount
                     response.write "<td>&nbsp;</td>" 'empty cell
                  next
              end if
        end if
        if col > colCount then
           col = 1 'reset
           response.write "</tr>" 'close row
        end if
    wend
    %>
    </table>
    Glenn
    vBulletin Mods That Rock!

    Comment


    • #3
      Thanks Glenn - you're a champion

      Comment


      • #4
        Glad to be of help.
        Glenn
        vBulletin Mods That Rock!

        Comment

        Working...
        X