Webmaster Forum


Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Coding Forum Problems with your code? Let's hear about it.

Ezilon Directory   ClickBooth Network   V7N Directory

Reply
 
LinkBack Thread Tools Display Modes
Old 02-26-2004, 10:04 AM   #1 (permalink)
Inactive
 
Pipeline-Webdesign's Avatar
 
Join Date: 02-11-04
Location: Corpus Christi, TX
Posts: 901
iTrader: 0 / 0%
Latest Blog:
None

Pipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the rough
Send a message via AIM to Pipeline-Webdesign Send a message via MSN to Pipeline-Webdesign Send a message via Yahoo to Pipeline-Webdesign
Random Image Loader

I have approxametly 10 images that I would like the browser to randomely pick from each time the page is loaded. Is there a simple script out there that would allow this to happen?

Michael
Pipeline-Webdesign is offline  
Add Post to del.icio.us
Reply With Quote
Sponsored Links
SEO Hosting by HostGator  Advertise Here  Buy Blog Links
Old 02-26-2004, 10:07 AM   #2 (permalink)
Inactive
 
Join Date: 10-13-03
Location: Finland
Posts: 640
iTrader: 0 / 0%
Latest Blog:
None

Cibok is just really niceCibok is just really niceCibok is just really niceCibok is just really niceCibok is just really niceCibok is just really niceCibok is just really niceCibok is just really niceCibok is just really niceCibok is just really nice
Send a message via ICQ to Cibok Send a message via AIM to Cibok Send a message via MSN to Cibok Send a message via Yahoo to Cibok
I belive that you're looking for an image rotator..
hotscripts.com is full of them..
Cibok is offline  
Add Post to del.icio.us
Reply With Quote
Old 02-26-2004, 10:49 AM   #3 (permalink)
Possible Terrorist
 
kwvarga's Avatar
 
Join Date: 10-13-03
Location: Tuscaloosa, AL or Atlanta
Posts: 4,904
iTrader: 0 / 0%
Latest Blog:
A+ Certification

kwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web pro
Send a message via AIM to kwvarga
[code:1:613fe2053d]
<?php
$location = "http://www.mysite.com/images/";
$files = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
$file = array_rand($files, 1)[0];
$ending = ".jpg";

$img = $location . $file . $ending;
echo "<img src="" . $img . "">";
?>[/code:1:613fe2053d]

quick and easy
__________________
Kyle Varga
"m3lt/theSpear"
student, web designer/coder, future IT consultant
Experience: PHP/MySQL, Java, C++, MS-SQL
kwvarga is offline  
Add Post to del.icio.us
Reply With Quote
Old 02-26-2004, 10:55 AM   #4 (permalink)
Inactive
 
Join Date: 10-12-03
Location: Cranberry Township
Posts: 275
iTrader: 0 / 0%
niceguyeddie is just really niceniceguyeddie is just really niceniceguyeddie is just really niceniceguyeddie is just really niceniceguyeddie is just really niceniceguyeddie is just really niceniceguyeddie is just really niceniceguyeddie is just really niceniceguyeddie is just really niceniceguyeddie is just really niceniceguyeddie is just really nice
Send a message via ICQ to niceguyeddie
Quote:
Originally Posted by theSpear
[code:1:d7404d5b3c]
<?php
$location = "http://www.mysite.com/images/";
$files = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
$file = array_rand($files, 1)[0];
$ending = ".jpg";

$img = $location . $file . $ending;
echo "<img src="" . $img . "">";
?>[/code:1:d7404d5b3c]
Or as a function.

[code:1:d7404d5b3c]
<?php
function random_image()
{
$location = "http://www.mysite.com/images/";
$files = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
$file = array_rand($files, 1)[0];
$ending = ".jpg";

$img = $location . $file . $ending;
return $img;
}
?>
[/code:1:d7404d5b3c]
niceguyeddie is offline  
Add Post to del.icio.us
Reply With Quote
Old 02-26-2004, 12:31 PM   #5 (permalink)
Moderator
 
LazyJim's Avatar
 
Join Date: 10-13-03
Location: UK
Posts: 2,819
iTrader: 0 / 0%
Latest Blog:
None

LazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to all
Send a message via MSN to LazyJim
[code:1:b893dd3e4e]echo "<img src="" . $img . "">"; [/code:1:b893dd3e4e]
Why not change that to [code:1:b893dd3e4e]echo "<img src="$img">"; [/code:1:b893dd3e4e]
Or will that cause trouble?
__________________

-LJ-

My advice is to look at each case individually, with an informed mind and an appropriately balanced and objective viewpoint.

Web Design and Development, Ipswich, UK.
My deviantArt
LazyJim is offline  
Add Post to del.icio.us
Reply With Quote
Old 02-26-2004, 12:46 PM   #6 (permalink)
Possible Terrorist
 
kwvarga's Avatar
 
Join Date: 10-13-03
Location: Tuscaloosa, AL or Atlanta
Posts: 4,904
iTrader: 0 / 0%
Latest Blog:
A+ Certification

kwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web pro
Send a message via AIM to kwvarga
it works... but tis not as easy to see errors.. just a programming habit of mine.. because I have to use it when i am doing arrays & stuff.. it keeps things clear..
this text is displayed... this text is a variable etc.
__________________
Kyle Varga
"m3lt/theSpear"
student, web designer/coder, future IT consultant
Experience: PHP/MySQL, Java, C++, MS-SQL
kwvarga is offline  
Add Post to del.icio.us
Reply With Quote
Old 02-26-2004, 12:46 PM   #7 (permalink)
Inactive
 
Pipeline-Webdesign's Avatar
 
Join Date: 02-11-04
Location: Corpus Christi, TX
Posts: 901
iTrader: 0 / 0%
Latest Blog:
None

Pipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the rough
Send a message via AIM to Pipeline-Webdesign Send a message via MSN to Pipeline-Webdesign Send a message via Yahoo to Pipeline-Webdesign
Quote:
Originally Posted by theSpear
[code:1:3c3e229642]
<?php
$location = "http://www.mysite.com/images/";
$files = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
$file = array_rand($files, 1)[0];
$ending = ".jpg";

$img = $location . $file . $ending;
echo "<img src="" . $img . "">";
?>[/code:1:3c3e229642]

quick and easy
would that code go at the top of my coding or where the image needs to be placed? ... and is any of this code need to be edited besides the location of my images?
Pipeline-Webdesign is offline  
Add Post to del.icio.us
Reply With Quote
Old 02-26-2004, 12:49 PM   #8 (permalink)
Possible Terrorist
 
kwvarga's Avatar
 
Join Date: 10-13-03
Location: Tuscaloosa, AL or Atlanta
Posts: 4,904
iTrader: 0 / 0%
Latest Blog:
A+ Certification

kwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web pro
Send a message via AIM to kwvarga
that would go where it needs to be placed.. if you want more than 1 random image then you would use the function that niceguyeddie posted.. then just [code:1:7aa6573cbe]<?php echo "<img src="" . random_image() . "">"; ?>[/code:1:7aa6573cbe] where you would want the image.. the actual function code be anywhere inside <?php ?> tags at the end of the file.. wherever you want it..
__________________
Kyle Varga
"m3lt/theSpear"
student, web designer/coder, future IT consultant
Experience: PHP/MySQL, Java, C++, MS-SQL
kwvarga is offline  
Add Post to del.icio.us
Reply With Quote
Old 02-26-2004, 12:52 PM   #9 (permalink)
Moderator
 
LazyJim's Avatar
 
Join Date: 10-13-03
Location: UK
Posts: 2,819
iTrader: 0 / 0%
Latest Blog:
None

LazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to all
Send a message via MSN to LazyJim
anyway, if you wan't it to happen on the browser, as requested, then a JavaScript way...
Put this in you document first (in the <head> section idealy):
[code:1:7ddbe4fb49]
<script>
var url_before = "/images/image_";
var url_after = ".gif";
var min = 1;
var max = 10;
function printRndImg() {
document.write('<img src="' + url_before + ( min + Math.round(Math.random()*(max-min)) ) + url_after + '" boorder="0">')
}
</script>
[/code:1:7ddbe4fb49]
and set the variables up with you values, then put this anywhere you want an image:
[code:1:7ddbe4fb49]<script>printRndImg();</script>[/code:1:7ddbe4fb49]
__________________

-LJ-

My advice is to look at each case individually, with an informed mind and an appropriately balanced and objective viewpoint.

Web Design and Development, Ipswich, UK.
My deviantArt
LazyJim is offline  
Add Post to del.icio.us
Reply With Quote
Old 02-26-2004, 01:12 PM   #10 (permalink)
Inactive
 
Pipeline-Webdesign's Avatar
 
Join Date: 02-11-04
Location: Corpus Christi, TX
Posts: 901
iTrader: 0 / 0%
Latest Blog:
None

Pipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the rough
Send a message via AIM to Pipeline-Webdesign Send a message via MSN to Pipeline-Webdesign Send a message via Yahoo to Pipeline-Webdesign
Quote:
Originally Posted by LazyJim
anyway, if you wan't it to happen on the browser, as requested, then a JavaScript way...
Put this in you document first (in the <head> section idealy):
[code:1:d6195335d3]
<script>
var url_before = "/images/image_";
var url_after = ".gif";
var min = 1;
var max = 10;
function printRndImg() {
document.write('<img src="' + url_before + ( min + Math.round(Math.random()*(max-min)) ) + url_after + '" boorder="0">')
}
</script>
[/code:1:d6195335d3]
and set the variables up with you values, then put this anywhere you want an image:
[code:1:d6195335d3]<script>printRndImg();</script>[/code:1:d6195335d3]
i like this script alot better... much cleaner... but for some reason it's giving me a red X error... i've got my paths set right... any help?
Pipeline-Webdesign is offline  
Add Post to del.icio.us
Reply With Quote
Old 02-26-2004, 01:24 PM   #11 (permalink)
Inactive
 
Pipeline-Webdesign's Avatar
 
Join Date: 02-11-04
Location: Corpus Christi, TX
Posts: 901
iTrader: 0 / 0%
Latest Blog:
None

Pipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the roughPipeline-Webdesign is a jewel in the rough
Send a message via AIM to Pipeline-Webdesign Send a message via MSN to Pipeline-Webdesign Send a message via Yahoo to Pipeline-Webdesign
nvm... i had my images named incorrectly... thanks everyone for you help!!
Pipeline-Webdesign is offline  
Add Post to del.icio.us
Reply With Quote
Old 02-26-2004, 01:48 PM   #12 (permalink)
Moderator
 
LazyJim's Avatar
 
Join Date: 10-13-03
Location: UK
Posts: 2,819
iTrader: 0 / 0%
Latest Blog:
None

LazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to all
Send a message via MSN to LazyJim
no probs
__________________

-LJ-

My advice is to look at each case individually, with an informed mind and an appropriately balanced and objective viewpoint.

Web Design and Development, Ipswich, UK.
My deviantArt
LazyJim is offline  
Add Post to del.icio.us
Reply With Quote
Old 03-02-2004, 09:59 AM   #13 (permalink)
Inactive
 
Join Date: 10-17-03
Posts: 146
iTrader: 0 / 0%
Latest Blog:
Back online!

CrAg is liked by somebodyCrAg is liked by somebodyCrAg is liked by somebodyCrAg is liked by somebodyCrAg is liked by somebody
Send a message via ICQ to CrAg
Is there some kind of way to make the random images and links. I mean for example I have 5 banners and I want to link them to 5 different sites. Is it possible to do this?
CrAg is offline  
Add Post to del.icio.us
Reply With Quote
Old 03-02-2004, 10:33 AM   #14 (permalink)
Inactive
 
Join Date: 01-12-04
Posts: 999
iTrader: 0 / 0%
Latest Blog:
None

Emancipator is a jewel in the roughEmancipator is a jewel in the roughEmancipator is a jewel in the roughEmancipator is a jewel in the roughEmancipator is a jewel in the roughEmancipator is a jewel in the rough
Send a message via MSN to Emancipator
Yes the code example I posted does exactly that. You can even set the alt tags.

Just include the file in your html page.
Emancipator is offline  
Add Post to del.icio.us
Reply With Quote
Old 03-02-2004, 03:50 PM   #15 (permalink)
Inactive
 
Join Date: 10-17-03
Posts: 146
iTrader: 0 / 0%
Latest Blog:
Back online!

CrAg is liked by somebodyCrAg is liked by somebodyCrAg is liked by somebodyCrAg is liked by somebodyCrAg is liked by somebody
Send a message via ICQ to CrAg
Quote:
Originally Posted by LazyJim
anyway, if you wan't it to happen on the browser, as requested, then a JavaScript way...
Put this in you document first (in the <head> section idealy):
[code:1:4975e6cfc9]
<script>
var url_before = "/images/image_";
var url_after = ".gif";
var min = 1;
var max = 10;
function printRndImg() {
document.write('<img src="' + url_before + ( min + Math.round(Math.random()*(max-min)) ) + url_after + '" boorder="0">')
}
</script>
[/code:1:4975e6cfc9]
and set the variables up with you values, then put this anywhere you want an image:
[code:1:4975e6cfc9]<script>printRndImg();</script>[/code:1:4975e6cfc9]
OK!
I've got this script to work. How can I make that each picture has it's own link?
CrAg is offline  
Add Post to del.icio.us
Reply With Quote
Old 03-03-2004, 01:30 PM   #16 (permalink)
Moderator
 
LazyJim's Avatar
 
Join Date: 10-13-03
Location: UK
Posts: 2,819
iTrader: 0 / 0%
Latest Blog:
None

LazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to all
Send a message via MSN to LazyJim
insert the <script>printRndImg();</script> into a link:

[code:1:048911ba22]<a href="somelink.html"><script>printRndImg();</script></a>[/code:1:048911ba22]
__________________

-LJ-

My advice is to look at each case individually, with an informed mind and an appropriately balanced and objective viewpoint.

Web Design and Development, Ipswich, UK.
My deviantArt
LazyJim is offline  
Add Post to del.icio.us
Reply With Quote
Old 03-03-2004, 02:14 PM   #17 (permalink)
Inactive
 
Join Date: 10-17-03
Posts: 146
iTrader: 0 / 0%
Latest Blog:
Back online!

CrAg is liked by somebodyCrAg is liked by somebodyCrAg is liked by somebodyCrAg is liked by somebodyCrAg is liked by somebody
Send a message via ICQ to CrAg
Quote:
Originally Posted by LazyJim
insert the <script>printRndImg();</script> into a link:

[code:1:cc387717b2]<a href="somelink.html"><script>printRndImg();</script></a>[/code:1:cc387717b2]
Well, I know that. I do not need this. I need different link for different pictures. So each random picture will have it's own link.
CrAg is offline  
Add Post to del.icio.us
Reply With Quote
Old 03-03-2004, 03:34 PM   #18 (permalink)
Moderator
 
LazyJim's Avatar
 
Join Date: 10-13-03
Location: UK
Posts: 2,819
iTrader: 0 / 0%
Latest Blog:
None

LazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to all
Send a message via MSN to LazyJim
oh right, so you never wanted a random image thingy at all (link to your post).

A banner rotation script, or in you case a random banner script, is a little different.

You should use PHP...

in your HTML (but the file needs a .php extension):
[code:1:51c6e88e8a]
<?php
$banner_min = 1;
$banner_max = 4;
$random_banner_number = rand($banner_min, $banner_max);
echo include("banner_$random_banner_number.php");
?>
[/code:1:51c6e88e8a]
and then create 4 files called "banner_X.php" where X is a number from 1 to 4. You can change those numbers to any number, but make sure you also change the $banner_min and $banner_max in the script above. These 4 files I said have a .php extension, but they only need HTML in them, (they can have PHP if you want), or even just text, they just need to be the code for the banner, for example:
[code:1:51c6e88e8a]<a href="link1.html" target="_blank"><img src="image_1.gif"></a>[/code:1:51c6e88e8a]
__________________

-LJ-

My advice is to look at each case individually, with an informed mind and an appropriately balanced and objective viewpoint.

Web Design and Development, Ipswich, UK.
My deviantArt
LazyJim is offline  
Add Post to del.icio.us
Reply With Quote
Old 03-03-2004, 06:22 PM   #19 (permalink)
Inactive
 
Join Date: 10-17-03
Posts: 146
iTrader: 0 / 0%
Latest Blog:
Back online!

CrAg is liked by somebodyCrAg is liked by somebodyCrAg is liked by somebodyCrAg is liked by somebodyCrAg is liked by somebody
Send a message via ICQ to CrAg
Quote:
Originally Posted by LazyJim
oh right, so you never wanted a random image thingy at all (link to your post).

A banner rotation script, or in you case a random banner script, is a little different.

You should use PHP...

in your HTML (but the file needs a .php extension):
[code:1:05a94f25fc]
<?php
$banner_min = 1;
$banner_max = 4;
$random_banner_number = rand($banner_min, $banner_max);
echo include("banner_$random_banner_number.php");
?>
[/code:1:05a94f25fc]
and then create 4 files called "banner_X.php" where X is a number from 1 to 4. You can change those numbers to any number, but make sure you also change the $banner_min and $banner_max in the script above. These 4 files I said have a .php extension, but they only need HTML in them, (they can have PHP if you want), or even just text, they just need to be the code for the banner, for example:
[code:1:05a94f25fc]<a href="link1.html" target="_blank"><img src="image_1.gif"></a>[/code:1:05a94f25fc]
Well, at first I needed the Image Rotator. But then I also thought about banner rotator and thought I could do this with that script.

Ok. Let me try this script you just gave me. Next question, If I want to place this banner to some other page, how can I include them then? Like this:[code:1:05a94f25fc]<img src="page.php"></img>[/code:1:05a94f25fc]
CrAg is offline  
Add Post to del.icio.us
Reply With Quote