php - Random banner change and not displaying the first image whenever it complete the cycle -


actually have 10 banner , want change random when page refresh. banner change , complete cycle of 10 banners before repeating it..

i using code

$banners=$objcms->getbanners(); for($count=0;$count<count($banners);$count++) {     $image[$count]['path']= $banners[$count]['path'];     $image[$count]['bid']= $banners[$count]['bid'];     $image[$count]['bannerlink']=$banners[$count]['bannerlink'];     $image[$count]['name']=$banners[$count]['banner_name'];     $image[$count]['url']=$banners[$count]['bannerlink'];  } $banneradtotals=count($image)-1;  if($banneradtotals>0) {    //mt_srand((double)microtime() * 1234567);    $bannerpicked = mt_rand(0,$banneradtotals);  } else {    $bannerpicked = 0; }  ?> 

...................banner show here.................

please me............

here example session:

session_start(); // check last image loaded if (isset($_session['currentimage'])) {    $imgcounter = (int) $_session['currentimage'] + 1; }else {    $imgcounter = $_session['currentimage'] = 0; } if ($imgcounter > 10) {   $imgcounter = $_session['currentimage'] = 0; }  $currentimage = "/images/image{$imgcounter}.jpg";  ....  <img src="<?php echo $currentimage?>" alt="" /> 

now have next image loaded everytime , if reaches 10 start over.

you might need tweak little make match code

** update **

for random can use rand(0,9) , check value returned use picture , remove equation


Comments

Popular posts from this blog

Cursor error with postgresql, pgpool and php -

c# - how to write client side events functions for the combobox items -

ssh client with paramiko (python) -