Display Random Text ASP Script - ASP Web Pro
  Active Server Pages Programming by ASP Web Pro

ASP Scripts

DISPLAY RANDOM TEXT

Ever wanted to display random tips or quotes on your website? Well, Look no further. Here is a random text displayer that we used on a website we built that displays a random tip every time the browser is refreshed.

The first thing you need to do is create a database with a table called tblQuickTips with these fields:
fID - autonumber
fTip - text field or memo field depending on how long your tips are

Then, start adding some tips to your database.

Next, create a page called randomtext.asp and copy the below code into your page:

<%
DIM mySQL, objRS
mySQL = "SELECT MAX(fID) AS MaxTip FROM tblContent_Quick_Tips"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open mySQL, objConn

Randomize
DIM intRecord
intRecord = Int(objRS("MaxTip") * Rnd + 1)
objRS.Close
Set objRS = Nothing

mySQL2 = "SELECT fTip FROM tblContent_Quick_Tips WHERE fID = '" & intRecord & "'"
Set objRS2 = Server.CreateObject("ADODB.Recordset")
objRS2.Open mySQL2, objConn

Response.Write objRS2("fText")

objRS2.Close
Set objRS2 = Nothing
%>

All done. Just publish your page and database and click refresh on your browser. Each time you refresh, a random tip will be displayed.

< Back to ASP Scripts


 

 

Main Menu
Home
ASP Scripts
ASP Tutorials
JavaScripts
Awards
Contact Us

Email This Page

Other Resources
ASP Web Hosting
Search Engine Submission
Programming Help

 

 

 

Other ASP Web Sites

Site Map

 

Last Updated:
22 March 2010