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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.