Click to See Complete Forum and Search --> : Random pic in Banner on reload


sheepo-designs
08-12-2005, 11:34 PM
I'm doing a website for a hockey league and I want to show random pictures of which I select to show up in the banner everytime the user visits a page.

Here's an example:

http://www.edge.ca/

Refresh the page a couple times, you'll see that the banner changes bands. Now, I dont want to do this in flash. Before they changed it to flash they also had the random bands upon reload. Can anyone help me out?

Thanks!

bathurst_guy
08-13-2005, 12:25 AM
Theyve done it with a mix of javascript and php, which is not needed, only one is.
Which way do you want to do it?
Does your server support php? If so do it that way.
Get Back

cbstudio
08-13-2005, 12:30 AM
This can easily be done with java script. With a code that says to load images with a certain name + a number. (ex- image1.jpg image2.jpg etc) You need to change the number of images to the amount that you want to rotate. the code is pretty self explanitory...

put this in the head

<script type="text/javascript" language="JavaScript">
NumberOfImagesToRotate = 10;
FirstPart = '<img src="image';
LastPart = '.jpg" width="300" height="500">';
function printImage() {
var r = Math.ceil(Math.random() * NumberOfImagesToRotate);
document.write(FirstPart + r + LastPart);
}
</script>


and this where you want the image to be

<script type="text/javascript" language="JavaScript"><!--
printImage();
//--></script>



i don't know how good you are with javascript and html, so if i didn't explain it well enough just tell me.

bathurst_guy
08-13-2005, 12:44 AM
it can be just as easily done with php, and more accessible, and you dont have to worry about javascript being disabled on the browser, thats why i asked if server supports php, as there is no point in telling about js if it can be avoided

sheepo-designs
08-13-2005, 09:01 AM
Well, my client is still searching for the right host. I've never done any PHP before, because I've never had such a host, but I'm eager to learn.

I'll use the JS for now, and when the time comes that I find the right host, I'll be sure to try out the PHP once it is provided.

Thanks both of you!

sheepo-designs
08-13-2005, 09:09 AM
umm... cbstudio sorry, a little confusion...where do I put the x number of images? DO I list them in the head script or do I have a PrintImage script for every picture I use?

cbstudio
08-13-2005, 02:22 PM
you put the number of image you have in the head part where it says "numberofimagestorotate" and you only need to put the printimage part in there once.

and once again be sure to name all the images you want to rotate imageNUMBER.jpg (ex- image5.jpg, image8.jpg etc)

sheepo-designs
08-13-2005, 03:28 PM
Ahhhh I see. Perfect! thanks a lot!

the tree
08-13-2005, 04:31 PM
This'd be easy in PHP<?
$number = 10; // Amount of images.
$before = 'titles/'; // What directory the images are in.
$after = '.png'; // Extention to files.

$occasion = rand(0,$number);

print "<img src=\"$before$occasion$after\" alt=\"Page title\" />";
?>

sheepo-designs
08-13-2005, 05:52 PM
Well, my client is still searching for the right host. I've never done any PHP before, because I've never had such a host, but I'm eager to learn.

I'll use the JS for now, and when the time comes that I find the right host, I'll be sure to try out the PHP once it is provided.

Thanks both of you!

:)