Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatic refresh with proverb

Status
Not open for further replies.

Bravogolf

Programmer
Nov 29, 2002
204
GB
Hello.
It has been a long time since I came here, as I can usually figure out the stuff I need.
Are all the regulars still here (Chris Hunt, Onpnt..)?

Anyways, I have a page that every time it refreshes, I would like it to display something else (like a new proverb each time the page refresh).

Any help at all would be very much appreciated..

Thanks
 
Hi bravogolf,

Some things you will need:
- database
- ability to use a server technology that allows you to talk to the database (asp, php, jsp, cfm)

You would populate the database with, say, a simple table containing the proverb. On page load, server-side, you request a random record (I'm sure once you know the specific applications you are going to use, people will be willing to post a decent query string to do this) and put the proverb text into a variable... and then echo that variable content to the page where appropriate.

So... next step... send us some details of what server technologies you are going to use!

Cheers,
Jeff
 
But surely it can be done upon refresh, as in each time the page is refreshed, it calls a function that retrieves a proverb, and writes/displays it?
 
That is correct... and it is exactly what I suggested doing.

I think you are assuming that you can use Javascript to communicate with a database of some kind. This is not the case (client-side). To access a database you need to communicate server-side using something like asp, jsp, php.

It may very well be possible to do something with the IE-for-windows-only exec() commands using Javascript... but that will, of course, not work on any other browser or platform.

Jeff
 
Or you could do it all client side with a JavaScript array and a function to randomly select and display 1 item from the array when the page loads.

I'd go with the Database option if possible.
And yes, it would pull a random proverb every time the page loads/is refreshed.
 
Hmmm

/Rubs chin thoughtfully.

Ok, thank you, Jeff, I should check here at work (intranet).
 
I don't think you need to go overboard with databases and suchlike just to do a simple random quote generator, unless you want to pick from thousands of proverbs.

Take a look at how I've done it in . The couplet at the top is produced by a simple javascript, where the possible options are hard-coded into the script. It changes every time you refresh. Folk with Javascript switched off won't see a quote - their loss, but not a show stopper.

By contrast, the random "Gem of the Day" link is generated server-side, albeit not from a database (yet) though it could be. It appears to all users, JS-enabled or not, but doesn't change on refresh.

That's probably more than you wanted to know. Feel free to rip off my script and bend it to your purpose, I nicked it from somebody myself!

-- Chris Hunt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top