Ever wanted to display a random line of text each time a page is loaded, well here is an easy way.

 

<!--- First we set a variable to hold your list of quotes each seperated with commas --->
<cfset myQuotes = "Welcome to my site., Hope you like what I'm giving you., Your going to love my site. ">
<!--- Next we set a random quote number set the 3 to the number of quotes you have --->
<cfset randomQuote = #RandRange(1, 3)#>
<!--- Now we output the quote using trim, to remove starting white space before quote 2 and 3 then use listGetAt to find the quote you want
if randomQuote is 2 the script will output Hope you like what I'm giving you. --->
<cfset displayQuote = #trim(listGetAt(myQuotes, randomQuote))#>

Hope this helps someone.

About This Tutorial
Author: John Ramon
Skill Level: Beginner 
 
 
 
Platforms Tested: CFMX7
Total Views: 21,334
Submission Date: April 26, 2007
Last Update Date: June 05, 2009
All Tutorials By This Autor: 2
Discuss This Tutorial
  • Yea, yea I know I made some mistakes back then but I completely forgot about this. Thanks for updating it for everyone.

  • nice, but a couple of quick comments: 1) you're overusing pound signs. and is more readable (IMO) that what you used. 2) i'd modify the randRange() to look like this: why? because now i can add (or remove) quotes to (or from) the list, and not have to worry about remembering to update the 2nd argument of the randRange() :)

Advertisement

Sponsored By...
Powered By...