Please Help!!! MOD function

Please support our ASP advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Reply

Join Date: Mar 2005
Posts: 1
Reputation: richyrb is an unknown quantity at this point 
Solved Threads: 0
richyrb richyrb is offline Offline
Newbie Poster

Please Help!!! MOD function

 
0
  #1
Mar 26th, 2005
ok its one of those things i can't get my head around it at all..

i dont know if it the code i have already thats causing the problem or the fact that i dont know how to do MOD properly..

its causing bad gray hair..

so if anyone else is able to point out how to correct the code.. it would be of great thanks...


i have included the whole asp page as to show you the whole script incase i missed something or something needs to be added to make it work.... thank you..

im trying to get the record from the DB to display 3 times on the row before going down to the next row..

HOPE someone can help and point me in the right direction...

thanks in advance..

  1. <%
  2. ' Constants ripped from adovbs.inc:
  3. Const adOpenStatic = 3
  4. Const adLockReadOnly = 1
  5. Const adCmdText = &H0001
  6.  
  7. ' Our own constants:
  8. Const PAGE_SIZE = 5 ' The size of our pages.
  9.  
  10. ' Declare our variables... always good practice!
  11. Dim strURL ' The URL of this page so the form will work
  12. ' no matter what this file is named.
  13.  
  14. Dim cnnSearch ' ADO connection
  15. Dim rstSearch ' ADO recordset
  16. Dim strDBPath ' path to our Access database (*.mdb) file
  17.  
  18. Dim strSQL ' The SQL Query we build on the fly
  19. Dim strSearch ' The text being looked for
  20.  
  21. Dim iPageCurrent ' The page we're currently on
  22. Dim iPageCount ' Number of pages of records
  23. Dim iRecordCount ' Count of the records returned
  24. Dim I ' Standard looping variable
  25. Dim x
  26.  
  27. ' Retreive the URL of this page from Server Variables
  28. strURL = Request.ServerVariables("URL")
  29.  
  30. ' Retreive the term being searched for. I'm doing it on
  31. ' the QS since that allows people to bookmark results.
  32. ' You could just as easily have used the form collection.
  33. strSearch = Request.QueryString("search")
  34. strSearch = Replace(strSearch, "'", "''")
  35.  
  36. ' Retrieve page to show or default to the first
  37. If Request.QueryString("page") = "" Then
  38. iPageCurrent = 1
  39. Else
  40. iPageCurrent = CInt(Request.QueryString("page"))
  41. End If
  42.  
  43. ' Since I'm doing this all in one page I need to see if anyone
  44. ' has searched for something. If they have we hit the DB.
  45. ' O/W I just show the search form and quit.
  46. %>
  47.  
  48.  
  49. <%
  50. If strSearch <> "" Then
  51. ' MapPath of virtual database file path to a physical path.
  52. ' If you want you could hard code a physical path here.
  53. strDBPath = Server.MapPath("/db/vagdb.mdb")
  54.  
  55.  
  56. ' Create an ADO Connection to connect to the sample database.
  57. ' We're using OLE DB but you could just as easily use ODBC or a DSN.
  58. Set cnnSearch = Server.CreateObject("ADODB.Connection")
  59.  
  60. ' This line is for the Access sample database:
  61. cnnSearch.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
  62.  
  63. ' We're actually using SQL Server so we use this line instead:
  64. 'cnnSearch.Open "Provider=SQLOLEDB;Data Source=10.2.1.214;" _
  65. ' & "Initial Catalog=samples;User Id=samples;Password=password;" _
  66. ' & "Connect Timeout=15;Network Library=dbmssocn;"
  67.  
  68. ' Build our query based on the input.
  69. strSQL = "SELECT EventID,PicName,Location,Date,EventName,Brand,Model " _
  70. & "FROM picture " _
  71. & "WHERE (EventID) LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
  72. & "ORDER BY PicName;"
  73.  
  74. ' Execute our query using the connection object. It automatically
  75. ' creates and returns a recordset which we store in our variable.
  76. Set rstSearch = Server.CreateObject("ADODB.Recordset")
  77. rstSearch.PageSize = PAGE_SIZE
  78. rstSearch.CacheSize = PAGE_SIZE
  79.  
  80. ' Open our recordset
  81. rstSearch.Open strSQL, cnnSearch, adOpenStatic, adLockReadOnly, adCmdText
  82.  
  83. ' Get a count of the number of records and pages
  84. ' for use in building the header and footer text.
  85. iRecordCount = rstSearch.RecordCount
  86. iPageCount = rstSearch.PageCount
  87.  
  88. If iRecordCount = 0 Then
  89. ' Display no records error.
  90. %>
  91. <p>
  92. No records found. Please try again.
  93. </p>
  94. <%
  95. Else
  96. ' Move to the page we need to show.
  97. rstSearch.AbsolutePage = iPageCurrent
  98.  
  99. ' Show a quick status line letting people know where they are:
  100. %>
  101.  
  102. <p><font face=verdana size=2 color=#5F5E5D>
  103. <%= iRecordCount %> Records Found.
  104. Displaying page <%= iPageCurrent %>
  105. of <%= iPageCount %>:
  106. </font>
  107. </p>
  108. <%
  109. ' Display a table of the data in the recordset. We loop through the
  110. ' recordset displaying the fields from the table and using MoveNext
  111. ' to increment to the next record. We stop when we reach EOF.
  112. ' For fun I'm combining some fields and showwing you can do more then
  113. ' just spit out the data in the form it is in in the table.
  114. %>
  115.  
  116. <%
  117.  
  118. iCellsPerRow = 3
  119.  
  120.  
  121. Do While Not rstSearch.EOF And rstSearch.AbsolutePage = iPageCurrent
  122.  
  123. For x = 1 to (ID)
  124.  
  125. If x MOD iCellsPerRow = 1 Then
  126.  
  127. %>
  128.  
  129. <table cellpadding=1 cellspacing=1 border=0 align=center width=90%>
  130. <tr>
  131. <td>
  132. <a href="/gallery/event/<%= rstSearch.Fields("EventID").Value %>/med/<%= rstSearch.Fields("PicName").Value %>.jpg" target="_blank">
  133. <img src="/gallery/event/<%= rstSearch.Fields("EventID").Value %>/thumb/<%= rstSearch.Fields("PicName").Value %>.jpg" border="0">
  134. </a>
  135.  
  136. </td>
  137.  
  138.  
  139.  
  140. <td>
  141.  
  142. <table cellpadding=0 cellspacing=0 border=0 align=center>
  143. <tr>
  144. <td>
  145. <font face=verdana size=2 color=#A0A0A0> <%= rstSearch.Fields("Brand").Value %> &nbsp; <%= rstSearch.Fields("Model").Value %></font></td>
  146. <tr>
  147. <tr>
  148. <td><font face=verdana size=2 color=#A0A0A0> <%= rstSearch.Fields("EventName").Value %> &nbsp; <%= rstSearch.Fields("Date").Value %></font></td>
  149. <tr>
  150. <td><font face=verdana size=2 color=#A0A0A0> <%= rstSearch.Fields("Location").Value %></font></td>
  151. <tr>
  152. </table>
  153.  
  154. </td>
  155.  
  156.  
  157. <td><a href="/gallery/event/<%= rstSearch.Fields("EventID").Value %>/med/<%= rstSearch.Fields("PicName").Value %>.jpg" target="_blank"><font face=verdana size=2 color=#A0A0A0> view</font></a></td>
  158.  
  159.  
  160.  
  161.  
  162.  
  163. <%
  164. If x MOD iCellsPerRow = 1 Then
  165. Response.write "</tr><tr>"
  166.  
  167.  
  168. rstSearch.MoveNext
  169. Loop
  170. %>
  171.  
  172. </tr>
  173.  
  174. </table>
  175. <%
  176. ' Now we need to show our navigation links:
  177.  
  178. ' Show "previous" and "next" page links which pass the page to
  179. ' view our search parameter. You could also use form buttons
  180. ' but I find this looks better.
  181. If iPageCurrent > 1 Then
  182. %>
  183. <font face="verdana" size="2" color="#5F5E5D">
  184. <a href="<%= strURL %>?search=<%= Server.URLEncode(strSearch) %>&page=<%= iPageCurrent - 1 %>"><font face="verdana" size="2" color="#5F5E5D">[&lt;&lt; Prev]</font></a>
  185. </font>
  186. <%
  187. End If
  188.  
  189.  
  190.  
  191. If iPageCurrent < iPageCount Then
  192. %>
  193. <font face="verdana" size="2" color="#5F5E5D">
  194. <a href="<%= strURL %>?search=<%= Server.URLEncode(strSearch) %>&page=<%= iPageCurrent + 1 %>"><font face="verdana" size="2" color="#5F5E5D">[Next &gt;&gt;]</font></a>
  195. </font>
  196. <%
  197. End If
  198. %>
  199. </p>
  200. <%
  201. End if
  202. ' Close our recordset and connection and dispose of the objects
  203. rstSearch.Close
  204. Set rstSearch = Nothing
  205. cnnSearch.Close
  206. Set cnnSearch = Nothing
  207. End If
  208. %>
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 166
Reputation: Lafinboy is an unknown quantity at this point 
Solved Threads: 7
Lafinboy's Avatar
Lafinboy Lafinboy is offline Offline
Junior Poster

Re: Please Help!!! MOD function

 
0
  #2
Apr 1st, 2005
The result of the MOD function is the remainder, as a whole integer that remains after the division takes place. Some simple examples:
  1. 1 MOD 3 = 2
  2. 2 MOD 3 = 1
  3. 3 MOD 3 = 0
  4. 4 MOD 3 = 1
  5. 5 MOD 3 = 2
  6. 6 MOD 3 = 0

The important point to note here is that if you test for the MOD function to = 0 then that will return true at every instance where the lead integer is completely divisible by the divisor, in this case 3. So, a very simple change is needed in your code, to change the MOD test from 1 to 0.
  1. If x MOD iCellsPerRow = 0 Then
If I've been a help please confirm by clicking the Add to Lafinboy's Reputation link in the header of this reply.

Lafinboy Productions
:: Website Design :: Website Development ::

Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC