CodeAve.com CodeAve.com - ASP - Random Functions
ASP
·Read/Write
·Script Writers
·Database Display
·Response Objects
·Server Variables
·Random Events
·Articles
·Miscellaneous
·Contents
·What's New?
JavaScript
CSS
HTML
Maps
Links
Mail List
Search
Sitemap


 


Random Db Observation
Most random content scripts involve the loading of arrays to call the one that you want to output. As the number of items you want to display randomly increases so may your need to serve them from a database rather than from large amounts of manually updated text files. The following code will select a random quote from the opening of the Simpsonís as well as display the observation number and the total number of observations found from the query.
View the Output
Text View
Print View
Mail this Link
Download the Code
View the Data

<%
' Create a connection to the Access db and select all observations
' where there was a blackboard at the show opening
accessdb="simpsons" 
cn="DRIVER={Microsoft Access Driver (*.mdb)};"
cn=cn & "DBQ=" & server.mappath(accessdb)
set rs = Server.CreateObject("ADODB.Recordset")
sql = "select blackboard from shows where blackboard <> '' " 
rs.Open sql, cn, 1, 3

' Sets total_records to the number of observation found
total_records=rs.recordcount

' Creates a random number from 1 to the total number of records found
randomize 
random_number=int(rnd*total_records)+1

' Move to the first record
rs.MoveFirst

' Start a loop that will continue until the random observation is found 
do while not rs.eof and counter <> random_number

' count the observations
counter = counter + 1 

' If the current observation = the random number out it
if counter= random_number then
response.write rs("blackboard") & "<br>"
response.write "Observation # " & random_number &" of " & total_records
end if ' end check for random observation

' Move to the next record
rs.movenext

' Loop back to the for statement
loop
%>

 

 

 



ASP: What's New? | Articles | Script Writers | Database Display | Read/Write
Server Variables | Response Objects | Random Events | Miscellaneous
HTML: Forms | Hyperlinks | Headers | Tables | Hyperlinks | Headers | Text Display
JavaScript: Document Info | Forms | Images | Navigation | Script Writers
CSS: Basics | Page Display | Text Display | Script Writers | Miscellaneous
  • 2014 michael kors
  • air max women 2013
  • 2014 michael kors
  • air max 2014
  • oakley glasses
  • oakley glasses

  • Maps: Map Script Writers | Bing Maps | Google Maps
  • bottes fr
  • ugg boot
  • Privacy Statement

    CodeAve.com is hosted by MyHosting.com
    Donate Food Online with a Mouse Click at TheHungerSite.com
    Donate Land Online with a Mouse Click at TheRainForestSite.com
    © 1999 - 2017 CodeAve.com
    All Rights Reserved

  • Kids jordan 6 rings
  • Jordan retro 10
  • Jordan retro 3