473,396 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Loop trough db with spacing..

80
Hi All!

I wonder, how can I loop trough a record in my database showing the first three matches in a cell structure, then create a new paragraph with the next three matches and so on..?

Thanks.
Frederik
Dec 18 '08 #1
4 1517
jhardman
3,406 Expert 2GB
I'm not sure how you want the HTML done, but you will need to count to three and every three you reset the timer and start the new line or paragraph. For example, if you were doing it in a table, you would do something like this:
Expand|Select|Wrap|Line Numbers
  1. dim x
  2. if not objRS.eof
  3.    response.write "<table><tr>" & vbNewLine
  4.  
  5.    x = 0
  6. do until objRS.eof
  7.    response.write "<td><p>" & objRS("title") & " - " & objRS("description") & "</td>" & vbNewLine
  8.    x = x + 1
  9.    if x = 3 then
  10.       response.write "</tr><tr>" & vbNewLine
  11.       x = 0
  12.    end if
  13.    objRS.movenext
  14. loop
  15. response.write "</tr></table>" & vbNewLine
  16. end if
There are a couple ways to structure the loop to get this same effect, but this is as good as any. Does this make sense?

Jared
Dec 18 '08 #2
Pheddy
80
Yeah sure, just needed some quidelines on how to construct the code, Im sure i will make it work from here. Thanks!
Dec 18 '08 #3
Pheddy
80
Hey again! I'm stuck on a problem with this code. I need to show a table with this code with two or three cells containing more than one info for each items. Quess I need to make a loop wihtin a loop. My code looks like this for now the underlaying cells are marked out. Can't seem to figure this out...

Expand|Select|Wrap|Line Numbers
  1. <%
  2. dim varSelectedChar
  3. dim x
  4. if Request.QueryString("l") = "" then
  5.   varSelectedChar = "a"
  6. else
  7.   varSelectedChar = Request.QueryString("l")
  8. end if
  9.  
  10. Set Conn = Server.CreateObject("ADODB.Connection")
  11. DSN = "DRIVER={Microsoft Access Driver (*.mdb)}; "
  12. DSN = DSN & "DBQ=" & Server.MapPath("db1.mdb")
  13. Conn.Open DSN
  14.  
  15. strSQL = "SELECT * FROM moveez WHERE m_titel LIKE '" & varSelectedChar & "%'"
  16. Set rs = Conn.Execute(strSQL)
  17.  
  18. if not rs.EOF then
  19.   response.write "<table border=""0"" cellpadding=""0"" style=""border-collapse: collapse"" width=""100%"">"
  20.   response.write "<tr>"
  21.  
  22.   x = 0 
  23. do until RS.eof 
  24.   'Response.Write "<td width=""5"">&nbsp;</td>"
  25.   Response.Write "<td width=""100""><a href=""?pid=details&fid=" & rs("ID") & """><img width=""80"" height=""100"" src=""/film/m_pic/" & RS("m_picture") & """></a></td>"
  26.  
  27.       'Response.Write "<td width=""5"">&nbsp;</td>"
  28.       'Response.Write "<td>" & rs("m_titel") & "</td>"
  29.  
  30.       'Response.Write "<td>&nbsp;</td>"
  31.       'Response.Write "<td>&nbsp;</td>"
  32.  
  33.   x = x + 1 
  34.     if x = 5 then 
  35.       response.write "</tr>"
  36.       response.write "<tr>" 
  37.     x = 0 
  38.     end if 
  39.       RS.movenext 
  40.       loop 
  41.  
  42.     response.write "</tr>" 
  43.     response.write "</table>"
  44.  
  45.   else
  46.     Response.Write("SOME ERROR (" & varSelectedChar & ")"
  47. end if
  48.  
  49. Conn.Close
  50. Set Conn = Nothing
  51. %>
Dec 19 '08 #4
jhardman
3,406 Expert 2GB
I'm not sure how this isn't working, you didn't say what was going wrong. Anyway, here's one thought. Whenever I need to write a lot of HTML markup including lots of quote marks, I dislike using the two double quotes solution, it seems to go wrong too often for me (and I know what I am doing) and I also see a lot of newbies making mistakes at it. It seems easier for me to declare a variable q = chr(34) and using that all the time for quote marks, or just dropping out of the vbscript temporarily like this:
Expand|Select|Wrap|Line Numbers
  1. '...
  2.  
  3. if not rs.EOF then %>
  4.   <table border="0" cellpadding="0" style="border-collapse: collapse" width="100%"><tr>
  5.    <%  
  6.   x = 0 
  7. do until RS.eof 
  8.   %>
  9.   <td width="100"><a href="?pid=details&fid=<%=rs("ID")%>"><img width="80" height="100" src="/film/m_pic/<%=RS("m_picture")%>"></a></td>
  10.    <%
  11. '...  
Not sure if that helps or not. Let me know.

Jared
Dec 24 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Rick DeBay | last post by:
I'm trying to create a layout table, where the spacing between rows varies. I've tried using setting margin-top and border-top for the rows I wan't spaced down from the one above, and I've also...
2
by: tony collier | last post by:
hi i have various labels on my page with ID's label_1, label_2 , label_3 etc. How can i write a loop that sequentially changes their text values to values i have in an array eg;. for...
2
by: Rvo | last post by:
I have written an application that manipulates files, while doing so the program is running in a loop and any actions on the GUI will not get any response. When I try to stop the processing of the...
4
by: metoikos | last post by:
I've scoured the web (clumsily, I'm sure) for information on the difficulties I am having, checked my markup in validators, and had a friend with more CSS clue look over it, but I haven't had any...
10
by: phil-news-nospam | last post by:
I have a table with 3 columns in 1 row. I want to increase the spacing _between_ the columns (gutter) _without_ increasing the spacing between those columns and the table itself. Is there a way...
1
by: shapper | last post by:
Hello, I created a connection to a database and everything is fine. Finally I wrote this: connection.Open() **** MyFunction( , , ) **** connection.Close()
23
by: Sacred Heart | last post by:
Hi, I'm new to Python and have come across a problem I don't know how to solve, enter com.lang.python :) I'm writing some small apps to learn the language, and I like it a lot so far. My...
2
by: GlenC | last post by:
Hello everyone, I'm brand new to this forum and have not yet trolled through all the posts so bear with me please. I am a beginner at VB.Net programming (using VB express 2008) and (of course)...
1
by: GlenC | last post by:
Hello everyone, I'm brand new to this forum and have not yet trolled through all the posts so bear with me please. I am a beginner at VB.Net programming (using VB express 2008) and (of course)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.