Monday, September 24th, 2007 08:52 am
Hm. Anyone on my f-list know how to set up the .php code for a 'rotating' set of banners on a regular webpage? Anyone on my f-list know how to explain to me how to set up the .php code for a 'rotating' set of banners on a regular webpage?
Sunday, September 23rd, 2007 11:23 pm (UTC)
The easiest way I know is the following...

<?php $ri=rand(0,10); ?>
<img src="<?php echo $ri; ?>">


Whereby you insert this code where the image goes, you change the extension to whatever image type you are using, and the images in the rotation are numbered from 1-10 and placed in the same folder as the file containing this script. Of course, this has to be a .php file for this to work...

If you have another code in mind, let me have it and I might be able to help you with that...
Sunday, September 23rd, 2007 11:55 pm (UTC)
Files can be a combination of HTML and PHP, however, for this code to work, all the pages need the extention .php rather than .html. No recoding is necessary - you'd just put this code in the HTML where the existing image is.

There are ways to do it with scripts that are linked in - these are more flexible - however they still require a .php extension to run since they use an include to make the script execute.

Ergo, whichever way you do it, to use PHP to do this, you have a lot of extension renaming in your future.
Monday, September 24th, 2007 12:34 am (UTC)
I do believe you can also do this with a JavaScript...
Sunday, September 23rd, 2007 11:59 pm (UTC)
And yes, it would be 1.jpg, 2.jpg, etc...

You could probably folderise by adding folder/ before the PHP code in the img attribute.
Monday, September 24th, 2007 03:17 am (UTC)
Here's a site with JavaScript code

JavaScript (http://javascript.internet.com/miscellaneous/rotating-banner.html)

Monday, September 24th, 2007 03:28 am (UTC)
You're welcome :)
Sunday, September 23rd, 2007 11:23 pm (UTC)
The easiest way I know is the following...

<?php $ri=rand(0,10); ?>
<img src="<?php echo $ri; ?>">


Whereby you insert this code where the image goes, you change the extension to whatever image type you are using, and the images in the rotation are numbered from 1-10 and placed in the same folder as the file containing this script. Of course, this has to be a .php file for this to work...

If you have another code in mind, let me have it and I might be able to help you with that...
Sunday, September 23rd, 2007 11:55 pm (UTC)
Files can be a combination of HTML and PHP, however, for this code to work, all the pages need the extention .php rather than .html. No recoding is necessary - you'd just put this code in the HTML where the existing image is.

There are ways to do it with scripts that are linked in - these are more flexible - however they still require a .php extension to run since they use an include to make the script execute.

Ergo, whichever way you do it, to use PHP to do this, you have a lot of extension renaming in your future.
Monday, September 24th, 2007 12:34 am (UTC)
I do believe you can also do this with a JavaScript...
Sunday, September 23rd, 2007 11:59 pm (UTC)
And yes, it would be 1.jpg, 2.jpg, etc...

You could probably folderise by adding folder/ before the PHP code in the img attribute.
Monday, September 24th, 2007 03:17 am (UTC)
Here's a site with JavaScript code

JavaScript (http://javascript.internet.com/miscellaneous/rotating-banner.html)

Monday, September 24th, 2007 03:28 am (UTC)
You're welcome :)