I downloaded a class from http://www.phpclasses.org/browse/package/1978.html
Here is the code
<?php
/*
* AdRotator : Simple adrotator class
* vedanta dot barooah at gmail dot com
*/
# version 1.2
class AdRotator{
var $iMax="";
var $imageIndex="";
var $imageNames="";
var $linkNames="";
function AdRotator($images,$links=NULL){
if(!is_array($images)) die("error: cant find image array");
else{
$this->iMax=count($images);
$this->imageNames=$images;
$this->linkNames=$links;
}
}
function rotate($num){
if($num > $this->iMax) die("error: not enough images to randomize");
$image_index=array();
while(count($image_index)<$num){
$pin=rand(0,$this->iMax-1);
if(!in_array("$pin",$image_index))array_push($image_index,$pin);
}
$this->imageIndex=$image_index;
}
function getImages(){
$tmp=array();
for($idx=0;$idx<count($this->imageIndex);$idx++) array_push($tmp,$this->imageNames[$this->imageIndex[$idx]]);
return $tmp;
}
function showAds($orientation=NULL /* say VERTICAL if you need vertical orientation */,$link_style=NULL,$target="_blank" /* target to open pages in */,$image_style=NULL /* this is the css class that can be used */){
if(!$link_style){$link_style="text-decoration:none;";}
if(!$image_style){$image_style="background:#f0f0f0;";}
$html='';
for($idx=0;$idx<count($this->imageIndex);$idx++){
$html.="<a target='".$target."' style='".$link_style."' href='".$this->linkNames[$this->imageIndex[$idx]]."'><img border=0 src='".$this->imageNames[$this->imageIndex[$idx]]."' style='".$image_style."'></a>\n";
if($orientation=="VERTICAL")$html.="<br>\n";
}
return $html;
}
}
?>
This code goes in the page to display the ads
// include the main class file
include("adrotator.class.php");
// make a image pool as an array
$image_array = array($image_path);
$links_array = array($ad_url);
// instance of the class
$o = new AdRotator($image_array,$links_array);
// set the number of images to be shown
//$o->rotate(5);
// get the images in an array
//$img=$o->getImages();
I am getting an error that there are not enough images in the array to rotate.
You can see the image and link arrays at this page
If I specify more that 1 the error comes up. Currently I have the line
$o->rotate(5);
commented out so I donot get the error.
You can see from my page that I am getting data. The first display is all the data in the table. The second is the image paths and the third is the urls for the image links.
I am trying but this stuff is getting real frustrating. Maybe it is my in-expirence with using PHP classes.
There must be an easy way to shuffle ads in a vertical format from data taken from a table. Then Display it.
Any help would be appreciated.