| | |
Please Help!!! MOD function
Please support our ASP advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
•
•
Join Date: Mar 2005
Posts: 1
Reputation:
Solved Threads: 0
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..
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..

ASP Syntax (Toggle Plain Text)
<% ' Constants ripped from adovbs.inc: Const adOpenStatic = 3 Const adLockReadOnly = 1 Const adCmdText = &H0001 ' Our own constants: Const PAGE_SIZE = 5 ' The size of our pages. ' Declare our variables... always good practice! Dim strURL ' The URL of this page so the form will work ' no matter what this file is named. Dim cnnSearch ' ADO connection Dim rstSearch ' ADO recordset Dim strDBPath ' path to our Access database (*.mdb) file Dim strSQL ' The SQL Query we build on the fly Dim strSearch ' The text being looked for Dim iPageCurrent ' The page we're currently on Dim iPageCount ' Number of pages of records Dim iRecordCount ' Count of the records returned Dim I ' Standard looping variable Dim x ' Retreive the URL of this page from Server Variables strURL = Request.ServerVariables("URL") ' Retreive the term being searched for. I'm doing it on ' the QS since that allows people to bookmark results. ' You could just as easily have used the form collection. strSearch = Request.QueryString("search") strSearch = Replace(strSearch, "'", "''") ' Retrieve page to show or default to the first If Request.QueryString("page") = "" Then iPageCurrent = 1 Else iPageCurrent = CInt(Request.QueryString("page")) End If ' Since I'm doing this all in one page I need to see if anyone ' has searched for something. If they have we hit the DB. ' O/W I just show the search form and quit. %> <% If strSearch <> "" Then ' MapPath of virtual database file path to a physical path. ' If you want you could hard code a physical path here. strDBPath = Server.MapPath("/db/vagdb.mdb") ' Create an ADO Connection to connect to the sample database. ' We're using OLE DB but you could just as easily use ODBC or a DSN. Set cnnSearch = Server.CreateObject("ADODB.Connection") ' This line is for the Access sample database: cnnSearch.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";" ' We're actually using SQL Server so we use this line instead: 'cnnSearch.Open "Provider=SQLOLEDB;Data Source=10.2.1.214;" _ ' & "Initial Catalog=samples;User Id=samples;Password=password;" _ ' & "Connect Timeout=15;Network Library=dbmssocn;" ' Build our query based on the input. strSQL = "SELECT EventID,PicName,Location,Date,EventName,Brand,Model " _ & "FROM picture " _ & "WHERE (EventID) LIKE '%" & Replace(strSearch, "'", "''") & "%' " _ & "ORDER BY PicName;" ' Execute our query using the connection object. It automatically ' creates and returns a recordset which we store in our variable. Set rstSearch = Server.CreateObject("ADODB.Recordset") rstSearch.PageSize = PAGE_SIZE rstSearch.CacheSize = PAGE_SIZE ' Open our recordset rstSearch.Open strSQL, cnnSearch, adOpenStatic, adLockReadOnly, adCmdText ' Get a count of the number of records and pages ' for use in building the header and footer text. iRecordCount = rstSearch.RecordCount iPageCount = rstSearch.PageCount If iRecordCount = 0 Then ' Display no records error. %> <p> No records found. Please try again. </p> <% Else ' Move to the page we need to show. rstSearch.AbsolutePage = iPageCurrent ' Show a quick status line letting people know where they are: %> <p><font face=verdana size=2 color=#5F5E5D> <%= iRecordCount %> Records Found. Displaying page <%= iPageCurrent %> of <%= iPageCount %>: </font> </p> <% ' Display a table of the data in the recordset. We loop through the ' recordset displaying the fields from the table and using MoveNext ' to increment to the next record. We stop when we reach EOF. ' For fun I'm combining some fields and showwing you can do more then ' just spit out the data in the form it is in in the table. %> <% iCellsPerRow = 3 Do While Not rstSearch.EOF And rstSearch.AbsolutePage = iPageCurrent For x = 1 to (ID) If x MOD iCellsPerRow = 1 Then %> <table cellpadding=1 cellspacing=1 border=0 align=center width=90%> <tr> <td> <a href="/gallery/event/<%= rstSearch.Fields("EventID").Value %>/med/<%= rstSearch.Fields("PicName").Value %>.jpg" target="_blank"> <img src="/gallery/event/<%= rstSearch.Fields("EventID").Value %>/thumb/<%= rstSearch.Fields("PicName").Value %>.jpg" border="0"> </a> </td> <td> <table cellpadding=0 cellspacing=0 border=0 align=center> <tr> <td> <font face=verdana size=2 color=#A0A0A0> <%= rstSearch.Fields("Brand").Value %> <%= rstSearch.Fields("Model").Value %></font></td> <tr> <tr> <td><font face=verdana size=2 color=#A0A0A0> <%= rstSearch.Fields("EventName").Value %> <%= rstSearch.Fields("Date").Value %></font></td> <tr> <td><font face=verdana size=2 color=#A0A0A0> <%= rstSearch.Fields("Location").Value %></font></td> <tr> </table> </td> <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> <% If x MOD iCellsPerRow = 1 Then Response.write "</tr><tr>" rstSearch.MoveNext Loop %> </tr> </table> <% ' Now we need to show our navigation links: ' Show "previous" and "next" page links which pass the page to ' view our search parameter. You could also use form buttons ' but I find this looks better. If iPageCurrent > 1 Then %> <font face="verdana" size="2" color="#5F5E5D"> <a href="<%= strURL %>?search=<%= Server.URLEncode(strSearch) %>&page=<%= iPageCurrent - 1 %>"><font face="verdana" size="2" color="#5F5E5D">[<< Prev]</font></a> </font> <% End If If iPageCurrent < iPageCount Then %> <font face="verdana" size="2" color="#5F5E5D"> <a href="<%= strURL %>?search=<%= Server.URLEncode(strSearch) %>&page=<%= iPageCurrent + 1 %>"><font face="verdana" size="2" color="#5F5E5D">[Next >>]</font></a> </font> <% End If %> </p> <% End if ' Close our recordset and connection and dispose of the objects rstSearch.Close Set rstSearch = Nothing cnnSearch.Close Set cnnSearch = Nothing End If %>
The result of the MOD function is the remainder, as a whole integer that remains after the division takes place. Some simple examples:
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.
ASP Syntax (Toggle Plain Text)
1 MOD 3 = 2 2 MOD 3 = 1 3 MOD 3 = 0 4 MOD 3 = 1 5 MOD 3 = 2 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.
ASP Syntax (Toggle Plain Text)
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 ::
Lafinboy Productions
:: Website Design :: Website Development ::
![]() |
Similar Threads
- convert seconds to minutes, hours, days, months, years, etc. (C)
- numbering systems (Visual Basic 4 / 5 / 6)
- Urgent Help needed with Pascal programming (Pascal and Delphi)
- getattr function (Python)
- Question: How Do I Create A 3-Piece Webpage? (HTML and CSS)
- Recursion Program/Code I'm having issues with... (Java)
Other Threads in the ASP Forum
- Previous Thread: need help on I/O in AsP(ASAP PLEASE)
- Next Thread: Simple Counter Code
| Thread Tools | Search this Thread |
archive asp aspandmssqlserver2005 aspandmssqlserver2005connection aspconnection connection database databaseconnection dreamweaver excel fso msmsql mssql2005 mssqlserver2005 mssqlserver2005andasp mssqlserverandasp opentextfile record searchbox selectoption single specfic sqlserver sqlserverconnection





