PDA

View Full Version : random fact



Captain
14-06-2009, 11:24 AM
how do you make a random fact generator on your website that changes everytime you reload the page? :\

Johno
14-06-2009, 11:29 AM
Something like this would work I guess:


<?PHP

$facts = array();

$facts[0] = "In Australia, a dust-devil is called a \"willy-willy.\"";
$facts[1] = "Back in 1919, the Russian transplant pioneer Serge Voronoff made headlines by grafting monkey testicles onto human males.";
$facts[2] = "It takes eight and a half minutes for light to get from the sun to earth.";
$facts[3] = "The United States Mint once considered producing donut-shaped coins.";
$facts[4] = "Natural gas does not have any odor. In order to detect a gas leak, some gas companies add a chemical that smells similar like rotten eggs.";
$facts[5] = "There are approximately 90 people that have been frozen after their death.";
$facts[6] = "Japan uses the most energy per year than any other country.";
$facts[7] = "A galactic year is 250 million Earth-years. This is the time it takes for our solar system to make one revolution around the Milky Way Galaxy.";
$facts[8] = "By weight, the sun is 70% hydrogen, 28% helium, 1.5% carbon, nitrogen, and oxygen, and 0.5% all other elements.";
$facts[9] = "Central air conditioners use 98% more energy than ceiling fans.";

$number = rand(0,9);

echo $facts[$number];
?>

Dye
14-06-2009, 11:33 AM
Something like this would work I guess:


<?PHP

$facts = array();

$facts[0] = "Yellow";
$facts[1] = "Blue";
$facts[2] = "Green";
$facts[3] = "Pink";
$facts[4] = "Purple";
$facts[5] = "Maroon";
$facts[6] = "Brown";

$number = rand(0,6);

echo $facts[$number];
?>

Yeah that's a simple one, there are others out there, you just got to look and not be lazy.

Captain
14-06-2009, 11:37 AM
I've been looking about for about 30 minutes, all I can actually find is countdown generators and stuff -.-

+ cheers Johno! :) +rep

Johno
14-06-2009, 11:38 AM
No problem, replaced the original code with one with some actual facts :)

Captain
14-06-2009, 11:44 AM
Sorta new to creating websites and such so im using an already coded template.

How do I get the index page to display the fact generator? Ive saved it as a .php file already.

Ive also edited the index page to show


<div id="banner"><iframe name="banner" id="banner" src="content/facts.php" width="100%" height="55" frameborder="0" allowtransparency="yes" scrolling="No"></iframe> </div>

Johno
14-06-2009, 11:50 AM
I would just either put the code straight into the page (so paste the code where you want it to display) or use a php include.


<?PHP include_once "content/facts.php"; ?>

Captain
14-06-2009, 12:10 PM
but how do i put that in if I want it to keep in the same borders so it doesn't stretch the page?



<div id="container">

<div id="banner"><iframe name="banner" id="banner" src="content/news.html" width="100%" height="55" frameborder="0" allowtransparency="yes" scrolling="No"></iframe> </div>

<div id="marquee"></div>

where can i put the php code in there? :S

Johno
14-06-2009, 12:13 PM
well you could define the width of the div it needs to be in and then set it so the fact marquee's


<?PHP

$facts = array();

$facts[0] = "In Australia, a dust-devil is called a \"willy-willy.\"";
$facts[1] = "Back in 1919, the Russian transplant pioneer Serge Voronoff made headlines by grafting monkey testicles onto human males.";
$facts[2] = "It takes eight and a half minutes for light to get from the sun to earth.";
$facts[3] = "The United States Mint once considered producing donut-shaped coins.";
$facts[4] = "Natural gas does not have any odor. In order to detect a gas leak, some gas companies add a chemical that smells similar like rotten eggs.";
$facts[5] = "There are approximately 90 people that have been frozen after their death.";
$facts[6] = "Japan uses the most energy per year than any other country.";
$facts[7] = "A galactic year is 250 million Earth-years. This is the time it takes for our solar system to make one revolution around the Milky Way Galaxy.";
$facts[8] = "By weight, the sun is 70% hydrogen, 28% helium, 1.5% carbon, nitrogen, and oxygen, and 0.5% all other elements.";
$facts[9] = "Central air conditioners use 98% more energy than ceiling fans.";

$number = rand(0,9);

echo "<marquee>$facts[$number]</marquee>";
?>

Do you have a live version of the website, PM me if you dont want to post it here :)

Joshh
14-06-2009, 12:44 PM
www.habbosolutions.net

click 'webscripts' then 'custom scripts' and download the one on there, not the best but it's still one.

lick
14-06-2009, 02:31 PM
Sorry to hijack the thread lol but how do i include these in a html layout?

i want them i na part were the radio says is?

Protege
14-06-2009, 07:22 PM
You dont, it has to be a PHP page.

I'd do it like this...



<?php
$factsArray = array();

$factsArray[] = 'James is a god';
$factsArray[] = 'James is awesum in so many ways';
$factsArray[] = 'James is teh best in the worlds';
$factsArray[] = 'All of the above are facts, even dis one!';

echo $factsArray[ array_rand( $factsArray ) ];
?>


http://beta.safeupload.com/sandbox/random_fact.php

Want to hide these adverts? Register an account for free!