Jump to content

Random Banner


StirCrazy

Recommended Posts

Hi folks,

This is so simple I'm suprised I can't see the wood thru the trees.


How do i get $link to = $bannerlink_[i][b]plus a random number here?[/b][/i];


[code]$bannerlink_1 = "blah";
$bannergraphic_1 = "blah";
$bannerlink_2 = "blah";
$bannergraphic_2 = "blah";

// How many banners do you want to rotate
$banners = "2";

$random = rand(1, $banners);

$link = $bannerlink_{$random};
$banner = $bannergraphic_{$random};[/code]


Many Thanks, S.C>
Link to comment
https://forums.phpfreaks.com/topic/27698-random-banner/
Share on other sites

I wouldnt do it that way though, generating variables like that is a messy thing to do IMO.

I'd set it up like this:
[code]<?php
$Banners = Array(); // Init our banners
$Banners[] = Array( 'link' => 'blah', 'graphic' => 'blah' );
$Banners[] = Array( 'link' => 'blah', 'graphic' => 'blah' );
$Banners[] = Array( 'link' => 'blah', 'graphic' => 'blah' );
$Banners[] = Array( 'link' => 'blah', 'graphic' => 'blah' );

$Banner = $Banners[(rand(1, count($Banners)) - 1];
echo $Banner['link'] . '<br />';
echo $Banner['graphic'] . '<br />';
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/27698-random-banner/#findComment-126734
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.