You are invited to Log in or Register a free Frihost Account!

random content in page at every view?

Ray Gravin
I was wondering if there was a way to do this: I want to have a random blurb or qoute on my title page everytime someone visits my site. It would just be a few lines of text of course. Is there a way to do this? some way to command a random bit of text from a file or multiple files to be shown on one part of the page? Would I need to use frames?
I know that there are wordpress plugins for this (look in the codex at for this if you really need it. I would provide a link but my clipboard doesn't love me any more) but I have a feeling that you are not wordpress so I just waisted your time and got frih. Yay frih!
the easiest way to do that is by using php and mysql.

you make a table with all the random quotes that you want to show,


mysql> USE mydatabase;
Database changed
mysql> CREATE TABLE quotes (
        -> quote TEXT NOT NULL,
        -> PRIMARY KEY (quote_id)

mysql> INSERT INTO quotes (quote) VALUES
        -> ('I am a happy quote!'),
        -> ('I am another happy quote!');

then make your query. something like:



something like that, hope this helps! Very Happy
Ansother way is javascript....pretty simple.... just cut and paste.... but of course won't work worth a hill of beans if your visitor doesn't have javascript enabled...

this one is for a "quote of the day"

this one is kinda cool... still not quite what u wanted though, but this one scrolls your blubs ... and you can customize how fast etc...

and another one.. this is probably a bit closer to what u wanted..

and lastly theres this one which is probably the closest you'll get

Also, have you considered making your text into a banner? if you made a bunch of banners with your text and use a banner rotator script you can add color effects, pics etc to your blurbs to make them more visually stimulating.........
i would use this code:

      $text[1]='Quote 1';
      $text[2]='Quote 2';
      $randomtext = rand(1, count($text));


You can add as many as you like just add another $text bit
Ray Gravin
you guys are awsome : ) ... so what are the chances a visitor wouldnt have a java installed? It seems like a pretty mandatory part of web browsing these days. also is there anything a veiwer would need to install to run php? Ive never heard of it before? is it just a part of html or something?

thanks for your time guys you have been very helpfull : ) Im excited about this idea taking form for me : )
I assume you mean javascript, not java (although similar name, totally different)

it is an option in all browsers whether you wnt in enabled or not, and some people do prefer not to have in enabled for various reasons, although it isn't a large group of people.

Personally php is probably the better way to go if you want to be sure people see your effect.... but they are slightly more complicated if your not sure what your doing...although the ones i've found have pretty good instructions here... im a little disapointed that they don't have previews tho Sad

mind you, give it a try... see what you like and what you feel is more comfortable... worst thing that can happen is they don't work for you, and you try again...
One word of advice, only use something like editplus or notepad to edit your files with.. if you chose a rich text program (such as wordpad) your scripts won't work..
Ray Gravin
cool cool ... im working on a linux machine .... Im using bluefish editor.... i assume that should be ok for scripts?
Ray Gravin
Just in case anyone looks here for the same advice i was looking for the only suggestion here that I could get to work the way I wanted was one of the ones from jaysen's first post.


and lastly theres this one which is probably the closest you'll get

works like a charm : )

I wanted to use the php approach... but for some reason couldnt get the scripts i found here to work the way I wanted : ( ... mabe after i get used to html I will try and learn a litle php code or somthing.
Cool! Glad you got something to work for the time being..
Related topics
News and Comment system!
Google and Domains: help
Most random site ever!!!
Slight username problem.
Guess the term -- Back in Business!!!
The concept of FriHost [computeraki's manifesto]
Get country where server stands.
targeting <div> tags with links
PHP script problem
Server 2 - The connection has been reset
What to do if your site has content not suitable for kids?
Problem with Member system(or template) and $_GET[id]
Need some tips
Not able to find Login link on home page
Reply to topic    Frihost Forum Index -> Webmaster and Internet -> Design Tips

© 2005-2011 Frihost, forums powered by phpBB.