Hello. Im looking for some kind of script to randomise code what code to display when a page is loaded. For example if a page is loaded where i have have this script it displays "code1" and the next time the page is loaded "code2" maybe displays. Anyone know where i can find someting like this ?
modify this a bit http://www.crivionweb.com/phpblog/php-tutorial-random-banner-rotator/ instead of $banners = array("path/img1.jpg", "path/img2.gif"); you could add $banners = array("code1", "code2);
how many different options you have for randomization . Well you can just need a formula and you can use time stamp and modulo function as some of their parameter ..
for javascript: <script type="text/javascript"> var r=Math.floor(Math.random()*2) + 1; document.write("<script type='text\/javascript' src='script" + r + ".js'><\/script>"); </script> Code (markup): where the two scripts are 'script1.js' and 'script2.js' ... some slight modifications can allow as many different scripts as necessary.
It's best to avoid using javascript if possible because users might have their javascript disabled. So, processing the request on server-side is a better solution, ie: PHP, etc. - ads2help
You could do this with PHP if that's what you want: <?php //just some example $codes = 5; //amount of codes that can be shown $code_show = mt_rand(1,$codes); //generate random code ID switch($code_show) { case '1': //show code 1 break; case '2': //show code 2 break; //... etc etc } ?> Code (markup): Just an example, if that's what you mean. Could also be done with a database containing all codes for example, with all unique IDs then let it get a random ID and show the code belonging to that ID. Skyfe.
or <?php $item[0] = "blah.php"; $item[1] = "blah1.php"; $item[2] = "blah2.php"; echo ($item[rand(0, 2)]); ?> PHP: that should be simple enough... basically do anything you want with it in php, you could use include insted of echo or whatever