Jump to content

how to show a 3rd banner type


computel

Recommended Posts

I have this code that displays banners of two types.

 

 

 

a banner that shows 468x60 and then two random banners of 120x240 & 120x600 sizes

 

 

 

the banners are called by the script

 

 

<?=show_banner("1");?> & <?=show_banner("2");?>

 

 

 

I want to have a 3rd banner location of 728x90 and call it like this

 

 

 

<?=show_banner("3");?>

 

 

 

how would I change the code below to do this?

 

 

 

Thanks

 

 

 

 

function banner_sizes($s) {

$sizes_array = array("468x60", "120x240", "120x600");

$select = "<select name=\"BannerSize\">\n\t";

foreach($sizes_array as $b)
{
  if($s == $b)
  {
   $select .= "<option value=\"$b\" selected>$b</option>\n\t";
  }
  else
  {
   $select .= "<option value=\"$b\">$b</option>\n\t";
  }
}

$select .= "</select>";

return $select;

}

function show_banner($bs) {

/*
  $bs = 1 (468x60) and 2 (random from 120x240, 120x600)
*/

global $dir;

if($bs == '1')
{
  $new_bs = "('468x60')";
}
else
{
  $new_bs = "('120x240', '120x600')";
}

$q1 = "select * from games_banners where BannerSize in $new_bs order by rand() limit 0,1 ";
$r1 = mysql_query($q1) or die(mysql_error());
$a1 = mysql_fetch_array($r1);

if($a1[bannerType] == "link_code")
{
  $banner_html = $a1[LinkCode];
}
else
{
  $size = explode("x", $a1[bannerSize]);

  $banner_html = "<a href=\"$a1[bannerURL]\" target=\"_top\"><img src=\"http://$_SERVER[HTTP_HOST]$dir/bfiles/$a1[bannerFile]\" alt=\"$a1[bannerAlt]\" border=0 width=\"$size[0]\" height=\"$size[1]\"></a>";
}

return $banner_html;

}


 

Link to comment
Share on other sites

this is quite simple given that code.  First off you need to add the new size into the $sizes_array so that would be changed from:

 

$sizes_array = array("468x60", "120x240", "120x600"); to $sizes_array = array("468x60", "120x240", "120x600", "728x90");

 

Next we need to change the show_banner function to read your optional attribute of 3.

 

So change this:

if($bs == '1') {  $new_bs = "('468x60')"; } else {  $new_bs = "('120x240', '120x600')"; }

 

to this:

if($bs == '1') { 

$new_bs = "('468x60')";

} else if($bs == '3') { 

$new_bs = "('728x90')";

} else {

$new_bs = "('120x240', '120x600')";

}

[/code]

 

and it should work for you.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.