• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Can a n00b get some help?

ivorymagus

New Member
I need something very simple that I can understand. I'm trying to make a random picker, that randomly picker like, 1 of 8 things. And not just images, just a little section of html coding.
 
PHP:
<?

$random[1] = 'something1';
$random[2] = 'something2';
$random[3] = 'something3';
$random[4] = 'something4';

$num = rand(1, 4);

echo $random[$num];

?>

here is a general random generator. you can modify this to do anything your heart desires. Give it a try.
 
I'm a noob at programming too, but I think you just put in what you want it to randomly pick, where it says "something1"... etc. Seems like that would be what you'd do lol
 
First of all you should try and explain a bit more what it is exactly that you're trying to achieve, or point us to a page that does what you want.
Secondly, do you need it for a client side script (.html files) or can you use a server side language like ASP, PHP, etc?

What spec posted is PHP, it needs to go into a file that ends with .php and it needs to be supported by the server you're putting the file on.
 
Use this function to create an array with the wand's names
Code:
<script type="text/javascript">
<!--

function RandomWand(){
   var wands = new Array(8);
      wands[0] = "wand1";
      wands[1] = "wand2";
      wands[2] = "wand3";
      wands[3] = "wand4";
      wands[4] = "wand5";
      wands[5] = "wand6";
      wands[6] = "wand7";
      wands[7] = "wand8";

   num = Math.round(Math.random()*7);

   document.write( wands[num] );
}

-->
</script>

And use this when you want to show the wand's name to the user
Code:
<script>
RandomWand()
</script>

To add more, just increase the numbers and add a new wand to the array.

Try it out :classic2:
 
wands[x] is the variable
the text that will get displayed is the text associated with that var.

lets say wands[3] got picked, it'll display Wand3, the thing between the "" 's
So you could just change the info between the "bla" and there you go. one entry per line.

hugo posted 2 pieces.
The first piece goes into the <head></head> part of your .html file, while the second bit of code goes into the <body>, more exactly, where you want your random info to appear. You can insert it in the middle of a sentence for example or whatever you want.

Experiment a little, it's easy and you'll understand better
 
Back
Top