All source code in ASP/ VbScript Ask a ASP/ VbScript Pro Discussion Forum Categories All jobs in ASP/ VbScript
Quick Search for:  in language:    
Many,time,found,myself,needing,display,result
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
ASP/ VbScript Stats

 Code: 281,486. lines
 Jobs: 101. postings

 How to support the site

 
Sponsored by:

 
You are in:
 
Login

NEW! LEARNING CENTER
Special educational offers, white papers, webcasts, podcasts

  NEW! Download Rational Performance Tester V8 (download now)
  NEW! Download Rational Functional Tester V8 (download now)
  NEW! Download Rational Service Tester for SOA Quality V8 (download now)
  NEW! Teleconference: Quality In Action - Using Rational Quality Manager with Functional, Performance and Web Service Testing Products (download now)
  NEW! Introducing IBM Rational AppScan Developer Edition – easing security testing by non-security professionals (download now)

 

 


Latest postings for ASP/ VbScript.
Click here to see a screenshot of this code!Mess Officer Management System (Sistem Pengurusan Mess Pegawai)
By Mohd Fauzi on 11/23

(Screen Shot)

Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!



 
 
   

Display database results in 'pages'

Print
Email
 
VB icon
Submitted on: 6/4/2001 9:07:07 PM
By: Tim Feeley  
Level: Intermediate
User Rating: By 7 Users
Compatibility:ASP (Active Server Pages), HTML, VbScript (browser/client side)

Users have accessed this code 30999 times.
 
(About the author)
 
     Many a time I found myself needing to display results in 'page' form. And call me old fashioned, devoted to learning or just plain stoopid, but I'd much rather learn how to code something myself than just plug in variables and let a snotty frontpage wizard do it for me. So, here it is, simple code to divide records into 'pages' of your choosing.

 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!

    '**************************************
    ' for :Display database results in 'page
    '     s'
    '**************************************
    Free. Take it. Don't credit me. See if I care. Hrmpf.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    '**************************************
    ' Name: Display database results in 'pag
    '     es'
    ' Description:Many a time I found myself
    '     needing to display results in 'page' for
    '     m. And call me old fashioned, devoted to
    '     learning or just plain stoopid, but I'd 
    '     much rather learn how to code something 
    '     myself than just plug in variables and l
    '     et a snotty frontpage wizard do it for m
    '     e. 
    So, here it is, simple code To divide records into 'pages' of your choosing.
    ' By: Tim Feeley
    '
    ' Inputs:I'm assuming that you have a da
    '     tabase that will be used as an input. Th
    '     is will be discussed in the code.
    '
    ' Returns:A pretty paged list of entries
    '     :)
    '
    ' Assumes:There are a number of assumpti
    '     ons (basically page, table and database 
    '     names), but they're noted in the code an
    '     d are easy to customize.
    '
    ' Side Effects:Drowsiness (or at least I
    '     was after taking the time to code it..)
    '
    'This code is copyrighted and has    ' limited warranties.Please see http://w
    '     ww.Planet-Source-Code.com/vb/scripts/Sho
    '     wCode.asp?txtCodeId=6696&lngWId=4    'for details.    '**************************************
    
    <% 
    'Initialize the data environment using A
    '     DO.
    Set DBView = Server.CreateObject("ADODB.Recordset")
    'DSN smells. I use a connection on a fol
    '     der in my webpage.
    'simply replace the connection string wi
    '     th your own path/DSN.
    DBView.ActiveConnection = "Driver={Microsoft Access Driver (*.mdb)};DBQ=c:/inetpub/wwwroot/fpdb/blarp.mdb"
    ' MUCHOS IMPORTANT! The main function (R
    '     ecordSet) will not work
    ' if you omit this statement. Resist the
    '     urge to delete it!
    DBView.cursortype = 1 
    ' Do not delete the above line or your r
    '     ecordset will always return -1.
    ' This is the SQL, replace it with your 
    '     own
    ' (from is in brackets because i was a d
    '     0pe and made it my
    ' field name, so I needed to distinguish
    '     that i KNEW my syntax,
    ' and that it's only a field name.)
    DBView.Source = "SELECT [from], subject, date, message FROM messages ORDER BY Date DESC" 
    DBView.Open
    ' When the user navigates using the page
    '     list, it makes the querystring page=1,2,
    '     etc.
    ' This will determine the page
    pgs = request.querystring("page")
    ' If it's blank, set it to one.
    
    if pgs = "" Then pgs = 1 : rpg = 1
    
    ' RPG is basically a silly variable i ca
    '     me up with that
    ' is discontinued in this edition of my 
    '     code. But you can keep it.
    rpg = pgs
    ' This is used to determine how far to m
    '     ove in the recordset.
    pgs = ((pgs - 1) * 5) +1 
    ' We're only going to view 5 at a time (
    '     which is why 5 is there)
    ' You can change that number to whatever
    '     you want, just make sure to
    ' do it in the points ahead.
    ' Also, we're keeping a 'Curre' counter 
    '     to determine how many records
    ' we've displayed. After it's reached 5 
    '     (or whatever you want), we're stopping.
    Curre = 0
    ' Okay, let's loop (if we're not at the 
    '     end of the file.)
    	
    if Not DBView.EOF Then 
    ' We're moving it to the record of the p
    '     age we're starting from.
    DBView.Move (pgs - 1)
    	
    ' Change this 5 to whatever you want. Re
    '     member 'Curre' is just 
    ' how far we looped THIS time.
    While curre < 5 and Not DBView.EOF
    	'Basically, display the repeated results. I included my table here, but feel free To modify it With your own fields.
    %>
    <TR>
    <TD width="100%" bgcolor="#800000"><B><FONT face="Arial" size="3"><%=(DBView("Subject"))%></FONT></B></TD>
    </TR>
    <TR>
    <TD width="100%" class="tbody" align="right" bgcolor="#800000">By: <%=(DBView("from"))%><BR>Date: <%=(DBView("Date"))%></TD>
    </TR>
    <TR>
    <TD width="100%" class="tbody"><%=(DBView("Message"))%><BR></TD>
    </TR>
    <TR><TD width="100%" height="20"></TD></TR>
    <% DBView.MoveNext
    curre = curre +1
    wend
    ' Keep looping and moving records until 
    '     we reach 5 records per page,
    ' or the end of the file. This End If en
    '     ds the checking if we're at the End of t
    '     he file.
    	
    	End if
    %>
    < finish your HTML repeating reigon here, For example, close your table >
    <TD width="100%" bgcolor="#800000" class="tbody">Messages: <B><%=pgs%>-<%=pgs+(curre-1)%> </B>of <B><%=(DBView.RecordCount)%></B></TD></TR>
    <TR><TD width="100%" class="tbody">
    <%
    ' Okay, a few things. The HTML line with
    '     ASP 'embedded' displays what we're looki
    '     ng at. We start at the pgs number (the b
    '     eginning record)
    ' for example, 10 or 15. We're then addi
    '     ng how many records we could show to tha
    '     t number to get the end of the range. If
    '     all 5 cound be
    ' shown, we'll add 5, if not, we'll add 
    '     just what we displayed.
    			pqs = request.querystring("page")
    			if pqs = "" Then pqs = 1
    ' What page are we on again? The above c
    '     ode checks it. The code below this check
    '     s how many pages we'll need to fit all t
    '     he data.
    ' Change all the 5's to whatever number 
    '     you want.
    			
    			pages = int(dbview.recordcount \ 5)
    			if dbview.recordcount mod 5 <> 0 Then pages = pages + 1
    ' This code takes the numeric portion of
    '     the records divided by five, for example
    '     , if we had 7 records this would be 1.
    ' We then see if there's any left over d
    '     ata by using Mod and if so, add another 
    '     page to accomodate it.
    ' Start displaying it.
    			response.write("Pages: [")
    ' Loop through all the page numbers.
    			For AI = 1 To pages
    ' I used a bunch of IF's when debugging.
    '     If it bothers you, add an Else :P
    ' We just check to see if pqs (the varia
    '     ble used above to determine what page is
    '     being viewed) matches the loop
    ' if so, don't add a hyperlink.
    				if Cint(AI) = cint(pqs) Then response.write "   <B>" & ai & "</B>   " 
    				if cint(AI) <> cint(pqs) Then response.write "   <A href=""blarp.asp?page=" & ai & """>" & ai & "</A>   " 
    			Next
    			
    			response.write ("]")
    ' That's it. Note how in the link code, 
    '     the page is blarp.asp. Change this with 
    '     your own or you'll have a sad broken lin
    '     k.
    %>


Other 3 submission(s) by this author

 

 
 Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:
 
Your Vote!

What do you think of this code(in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
5/10/2004 2:57:57 PM

Im trying to use this code, but the recordcount keep showing the value "-1", can some body help me??? Thanks
(If this comment was disrespectful, please report it.)

 
7/30/2004 5:07:26 PMPhillip De Suze

You need to actually do something like this to get the recordcount
While not Rs.Eof
Count = count + 1
wend
or
Use a Forward Cursor type
(If this comment was disrespectful, please report it.)

 
2/17/2007 4:27:35 AMephraim a

nice code pleas send me related code?????
thank you

(If this comment was disrespectful, please report it.)

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author from the email account you registered on the site, so you can correspond directly.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
To post feedback, first please login.


 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | ASP/ VbScript Home | Site Home | Other Sites | Open Letter from Moderators | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997-2008 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.   Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.