I have to show some banners in a webpage.The number of banners will be with in 10 (max 10). I can set the number of banners and each banner folder in database. Banner images are stored in separate server folders based on category. Banners are showing in columns.
My code is, Here, long1,long2,...long10 are directory names from database
$array=array();
for($n=1;$n<=$long;$n++)
{
$files = array();
$dir=${'long'.$n};
if(is_dir($dir))
{
$openDir = opendir($dir);
while (false !== ($file = readdir($openDir)))
{
if ($file != "." && $file != "..")
{
$files[] = $file;
}
}
closedir($openDir);
}
mt_srand((double) microtime()*1000000);
$randnum = mt_rand(0,(sizeof($files)-1));
$arraycount=count($array);
for($index=0;$index<=$arraycount;$index++)
{
if(!in_array($array,$randnum))
{
$array[]=$randnum;
}
}
$img = $dir."/".$files[$randnum];
<input type="image" class="advt_image" src="<?=$img;?>" alt="" name=""/>
}
ex: if there is 7 banner set in database, I have to show 7 banners from different or same folder.(some banners will be from same folder). I need to avoid the duplicate banners each time when I display a webpage.
I have assigned an array to store each random numbers. Do I need to change anything in code? any thought/idea?
Thanks!