Displaying Random Quotes

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.



All ColdFusion Tutorials By Author: John Ramon
  • CF Mini Database Driven Calendar
    I know there are a few calendars on the tutorial list, but everyone of them has someone asking how can I link to my database. I will show a simple solution to do this with examples.
    Author: John Ramon
    Views: 8,593
    Posted Date: Friday, November 10, 2006
  • Displaying Random Quotes
    A very easy way to display a random quote each time the page is loaded.
    Author: John Ramon
    Views: 3,246
    Posted Date: Thursday, April 26, 2007