logo
g Text Version
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Sports
Travel & Culture
TV & Movies

dailyclick
Bored? Games!
Nutrition
Postcards
Take a Quiz
Rate My Photo

new
Creativity
Family Travel
Southwest USA
Irish Culture
Home Finance
Comedy Movies
Romance Novels


dailyclick
All times in EST

Full Schedule
g
g ASP Site

BellaOnline's ASP Editor

g

Fortune Cookie / Random Quote Code - Database

Guest Author - Lisa Shea

It's always fun to have a fortune cookie on your website, to give a random quote or fortune or message each time the visitor comes by. Note that this version requires a database to work.

First, you need a database with the quotes or fortunes or whatever you will be showing. Create a database table, fortunes, with two columns - the item_id and the item_desc. The item_id would be a running series of numbers such as 1, 2, 3, 4, and so on. The item_desc would be the actual fortune or quote. So it could be "beware of short men" or "the cat will bring you good luck" or any other quote you decide on.

The benefit of this method is that you can create as many rows as you could possibly desire, and the code never changes. The new rows automatically get added into your mix.

You now need to figure out how many rows are in the database to know what range to choose a random number in. How to use the SQL Max Function. That will give you MaxID.

Next, use this MaxID to come up with a random number between 1 and that top ID number. How to use the Randomize Function. Your randomize function would be:

CurrID = Int((MaxID * Rnd) + 1)

Now you have an ID number somewhere between 1 and the maximum ID in your database. Now all you have to do is select the matching phrase!

select item_desc from fortunes where item_id = CurrID;

That's it! Now you can show your item_desc to your user and have different fortunes, quotes, phrases or anything else appear each time they come back!

Fortune Cookie Code Using an Array
Sample ASP Code

Introduction to ASP Ebook

Download this ebook to get everything you need to know about learning ASP - from a step by step tutorial to function lists, sample code, common errors and solutions, and much more! 101 pages.
This site needs an editor - click to learn more!

Add Fortune+Cookie+%2F+Random+Quote+Code+%2D+Database to Twitter Add Fortune+Cookie+%2F+Random+Quote+Code+%2D+Database to Facebook Add Fortune+Cookie+%2F+Random+Quote+Code+%2D+Database to MySpace Add Fortune+Cookie+%2F+Random+Quote+Code+%2D+Database to Del.icio.us Digg Fortune+Cookie+%2F+Random+Quote+Code+%2D+Database Add Fortune+Cookie+%2F+Random+Quote+Code+%2D+Database to Yahoo My Web Add Fortune+Cookie+%2F+Random+Quote+Code+%2D+Database to Google Bookmarks Add Fortune+Cookie+%2F+Random+Quote+Code+%2D+Database to Stumbleupon Add Fortune+Cookie+%2F+Random+Quote+Code+%2D+Database to Reddit




RSS | Related Articles | Editor's Picks Articles | Top Ten Articles | Previous Features | Site Map


For FREE email updates, subscribe to the ASP Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor


Content copyright © 2014 by Lisa Shea. All rights reserved.
This content was written by Lisa Shea. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.

g


g features
Best uses for RSS

RSS and its future.

Force Download Dialog box with ASP

Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Poetry
Daily
Weekly
Monthly
Less than Monthly



BellaOnline on Facebook
g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2014 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor