Help Needed Regarding Javascript

  • cnusangam
  • Born
  • Born
  • cnusangam
  • Posts: 1

Post 3+ Months Ago

HI ,
This is Srinivas. I want to rotate the banners on the webpage. What I am looking for is when a user gets on to the page banners 1 should be displayed and when another user opens the same page on some other system he should get banner 2. I am displaying only 2 banners right now. And whether it is possible or not. If any one can suggest something on how to solve this.

Thanks & Regards
Srinivas Sangam
  • may
  • Proficient
  • Proficient
  • User avatar
  • Posts: 328
  • Loc: Holland [NL]

Post 3+ Months Ago

Use PHP ;)

Code: [ Select ]
 
<?php
$bnr[1]['link'] = "http://www.google.com";
$bnr[1]['img'] = "http://www.google.nl/intl/nl_nl/images/logo.gif";
$bnr[2]['link'] = "http://www.amis.nl";
$bnr[2]['img'] = "http://www.amis.nl/gfx/img_amis_logo.gif";
 
function GetBanner($BArray){
      $rnd = rand(1,count($BArray));      
      return  '<a href="'.$BArray[$rnd]['link'].'"><img src="'.$BArray[$rnd]['img'].'" alt="[x]" border="0"/></a>';
}
 
Echo GetBanner($bnr);
?>
  1.  
  2. <?php
  3. $bnr[1]['link'] = "http://www.google.com";
  4. $bnr[1]['img'] = "http://www.google.nl/intl/nl_nl/images/logo.gif";
  5. $bnr[2]['link'] = "http://www.amis.nl";
  6. $bnr[2]['img'] = "http://www.amis.nl/gfx/img_amis_logo.gif";
  7.  
  8. function GetBanner($BArray){
  9.       $rnd = rand(1,count($BArray));      
  10.       return  '<a href="'.$BArray[$rnd]['link'].'"><img src="'.$BArray[$rnd]['img'].'" alt="[x]" border="0"/></a>';
  11. }
  12.  
  13. Echo GetBanner($bnr);
  14. ?>


It might take some refreshes to see alternating banners with only two. (Chance is 50% either one is shown) Just add the same banner in multiple to add to the chance ^^

If your using php < 4.2.0 (older version) you need to add some seed to the random generator.
I.e. Add this in top of the function.

Code: [ Select ]
srand((double)microtime()*1000000);     


Hope this helps..

Rgrds.

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 37 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.