StirCrazy Posted November 18, 2006 Share Posted November 18, 2006 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 More sharing options...
StirCrazy Posted November 18, 2006 Author Share Posted November 18, 2006 Tried this too ~ doesn't work either :($random = rand(1, 5);$link = $bannerlink['$random'];$banner = $bannergraphic['$random']; Link to comment https://forums.phpfreaks.com/topic/27698-random-banner/#findComment-126694 Share on other sites More sharing options...
roopurt18 Posted November 18, 2006 Share Posted November 18, 2006 $link = ${'bannerlink_' . $random}; Link to comment https://forums.phpfreaks.com/topic/27698-random-banner/#findComment-126731 Share on other sites More sharing options...
roopurt18 Posted November 18, 2006 Share Posted November 18, 2006 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.