Current location: Hot Scripts Forums » Programming Languages » ASP » Display 3 items per row


Display 3 items per row

Reply
  #1 (permalink)  
Old 09-13-07, 09:34 AM
zanchi zanchi is offline
Newbie Coder
 
Join Date: Jul 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Display 3 items per row

Hi, I want to display 3 items per row. The following code displays only one item per row. Then if it is possible i need to have 15 items per page, that is 5 rows, the it will be another page (Next page) to display more items.

Thank very much

asp Code:
  1. <%
  2. set conn=Server.CreateObject("ADODB.Connection")
  3. conn.Provider="Microsoft.Jet.OLEDB.4.0"
  4. conn.Open(Server.Mappath("markcamilleri.mdb"))
  5.  
  6. set rs = Server.CreateObject("ADODB.recordset")
  7. rs.Open "SELECT ProductID, TemplateNumber, Description, Image1, Preview FROM templates WHERE CategoryID=1", conn
  8. 'If no record found, end.
  9.    if rs.eof then
  10.     response.Write("No Records")
  11.     'rs.Close
  12.     'Response.End
  13.    end if
  14. %>
  15.           </p>
  16.             <table border="0" cellpadding="10" cellspacing="10">
  17.               <%
  18. Do While Not rs.EOF
  19. %>
  20.               <tr>
  21.                 <td width="151"><img src="<%= rs.Fields("Image1").Value %>" width="215" height="199"></td>
  22.                 <td width="152"><%= rs.Fields("Description").Value %></td>
  23.                 <td width="233"><%= rs.Fields("TemplateNumber").Value %></td>
  24.                 <td width="233"><a href="<%= rs.Fields("Preview").Value %>" target="_blank">Preview</a>
  25.                 </td>
  26.               </tr>
  27.               <%
  28. rs.MoveNext
  29. Loop
  30. %>
  31.     </table>
  32.     <%
  33. ' Close our recordset and connection and dispose of the objects
  34. rs.Close
  35. set rs = Nothing
  36. conn.Close
  37. set conn = Nothing
  38.  
  39. %>

Last edited by Nico; 09-13-07 at 10:29 AM.
Reply With Quote
  #2 (permalink)  
Old 09-13-07, 02:48 PM
koncept
Guest
 
Posts: n/a
i dont have a sample or the time to write one now before class but what you need to do is create a counter that runs and do modulous (intcounter mod 3) and if that is 0 then insert </tr><tr> tags else continue. then to finish it out you will want another loop to fill in the blank spaces up to three if eof occurs before the end of a row

i'll be glad to help if you want to take another shot at it before i get some sample code dug up or written
Reply With Quote
  #3 (permalink)  
Old 04-17-10, 12:01 PM
v3rt1go v3rt1go is offline
New Member
 
Join Date: Apr 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
To avoid using another loop to fill in data you could do something like this:

<% index = 0 -%>
<% @products.each do |prod| -%>
<% if index%3 == 0 -%>
<tr>
<% end -%>
<td class="product">
product data goes here
</td>
<% if index%3 == 2 -%>
</tr>
<% end -%>
<% index +=1 -%>
<% end -%>

This way you'll open the tr tag if the result of the mod calculation is 0 and close the tr tag if the result is 2 (last element in the row). If you want to change the number of tds shown in a row just change the mod calculation like this: index%x = 0 for opening the tr tag and index%x = x-1 for closing the tr tag, where x is the number of tds you want to display. Don't forget to add 1 to the index at the end of the loop.

Edit: MY BAD the above code is Ruby, but it's the same for ASP. Just noticed what i was browsing )

Last edited by v3rt1go; 04-17-10 at 12:04 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to display result in row of 10 ? Edward Han PHP 9 02-17-05 07:10 AM
Need Epinions-lite system in PHP & MYSQL wali001 Job Offers & Assistance 4 01-12-04 06:02 AM


All times are GMT -5. The time now is 03:59 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.