<% Dim tempConnection, tempSQL, tempDatabase, totalJokes, key, setup, delivery ' ---------------------------------- ' Open a connection to the database. ' ---------------------------------- Set tempConnection = Server.CreateObject("ADODB.Connection") tempConnection.Open "Knock" ' -------------------------------------- ' Query for the total number of entries. ' -------------------------------------- tempSQL = "select count(*) as totalJokes from Knock" Set tempDatabase = tempConnection.Execute(tempSQL) totalJokes = tempDatabase("totalJokes") ' ---------------------------------------- ' Generate a random integer in that range. ' ---------------------------------------- Randomize() key = Int(totalJokes * Rnd() + 1) ' ---------------- ' Retrieve a joke. ' ---------------- tempSQL = "select * from Knock where Key=" & key Set tempDatabase = tempConnection.Execute(tempSQL) While ( NOT tempDatabase.EOF ) setup = tempDatabase("Setup") delivery = tempDatabase("Delivery") tempDatabase.MoveNext WEnd 'while ' ------------------------------------- ' Close the connection to the database. ' ------------------------------------- tempDatabase.Close tempConnection.Close Set tempDatabase = Nothing Set tempConnection = Nothing %> <% ' %>
Knock knock! <%= setup %> <%= delivery %> Would you like to hear another? Thank you!