Forum Moderators: coopster
$bannerCounter= 1;$bannerCode[$bannerCounter] = "<a href=\"http://example.com/categories.php?PARTNER=unstabletable\"><img src=\"http://unstabletable.example.net/affiliate/ad05.jpg\" border=\"0\"></a>";
$bannerCounter++;$bannerCode[$bannerCounter] = "<a href=\"http://www.example.com/redir.php?aff=8073\"><img src=\"http://unstabletable.example.net/affiliate/hp_ad.gif\" border=\"0\"></a>";
$bannerCounter++;$bannerAdTotals = $bannerCounter - 1;
if($bannerAdTotals>1)
{
mt_srand((double)microtime() * 1234567);
$bannerPicked = mt_rand(1, $bannerAdTotals);
}
else
{
$bannerPicked = 1;
}
$bannerAd = $bannerCode[$bannerPicked];
And using the following to call it from my pages:
<?
include_once("/home2/thatothe/public_html/unstabletable/ad_rotation.php");
echo "<div align='center'>$bannerAd</div>";
?>
My problem is that I call it multiple times on each page, but it always generates the same ad each time it's called. Make sense? So I end up with the same ad multiple times on each page, when I want *each* one to be generated randomly. Thanks :)
[edited by: coopster at 1:46 pm (utc) on Mar. 30, 2006]
[edit reason] generalized urls [/edit]
$cn = mysql_connect ("localhost","username","password"); mysql_select_db('database_name');
Then you need to create your banner table so execute this code!
ONLY EXECUTE THIS CODE ONCE
<?
CREATE TABLE `banner`
(
`banner_img` VARCHAR (255) DEFAULT '0'
)
Then once you have the table you simply need to insert the data (img file) ...
Something like ... ONLY EXECUTE THIS CODE WHEN YOU HAVE A NEW BANNER TO ADD ...
<?
$sql = "INSERT INTO banner SET banner_img = 'imgfilehere.gif'";
if(mysql_query($sql))
{
echo 'Banner has been added';
}
else
{
echo 'Banner can\'t be added';
};
?>
Then once you have the banner images stored in the database you need to select a random banner img
<?
$sql_sel = "SELECT * FROM banner ORDER BY banner RAND()";
$res_sel = mysql_query($sql_sel);
$row = mysql_fetch_array($res_sel);echo '<img src="/folder/'.$row['banner_img'].'">';
?>
NOTE: This is not how i reccomend you should add to the database you should create some kind of management system to manage what banners are visible etc...
... this code hasn't been tested and may not work! sorry ...
However i hope i have helped.
Del
[edited by: coopster at 3:31 pm (utc) on Mar. 30, 2006]
[edit reason] unlinked url [/edit]
<?
// put the image banners in an array
$banners = array("image1.gif","image2.gif","image3.gif");
// put the urls in an array
$urls = array("www.google.co.uk","www.amazon.co","www.yoursite.com");
// count the banners for max randomness ;)
$count = count($banners)-1;
// select the random number
$rand = rand(0,$count);
// select the random url and banner!
echo '<a href="'.$urls[$rand].'"><img border="0" alt="'.$urls[$rand].'" src="'.$banners[$rand].'"></a>';
?>
Is this more what you was looking for?
Del
<a href="'.$urls[$rand].'">or
<img src="/folder/'.$row['banner_img'].'">';
Thanks:)
also if you want to look into packages take a look at [phpadsnew.com...]