Jump to content

[SOLVED] PHP Ad rotator


spikypunker

Recommended Posts

Haha!

 

My fault, i dunno what happened but i'd put the function in wrong!

 

It's now working and i'm well chuffed!!! WOOOOO, for anyone who wnats to use this script, here is the final working two pages..

 

ad_function.php

<?php

function ads(){

mysql_connect("localhost", "****", "****"); 

@mysql_select_db("****") or die ("unable to connect"); 


   $limit = 8; //number of ad spaces on the page
   $large = 2; //number of full sized add spaces on your page
   $small = $limit - $large;

   $query_large = mysql_query("SELECT * FROM ads WHERE large = \"YES\" ORDER BY Rand() LIMIT $large");
   
   $i=0;
   
   while($sql=mysql_fetch_array($query_large)){

      

      if($i < $large){
         $ad["ad"][$i]=$sql["full_ad"]; //URL for full sized ad banner
         $ad["url"][$i]=$sql["add_url"]; //URL for full sized  ad banner to redirect to website
         $i++;
       
      }
   }
   
   $query_small = mysql_query("SELECT * FROM ads WHERE large = \"NO\" ORDER BY Rand() LIMIT $small");
   
   $i=0;
   
   while($sql=mysql_fetch_array($query_small)){

      if($i < $small){
         $ad["ad"][$i+$large+1]=$sql["small_ad"]; //URL for small sized banner
         $ad["url"][$i+$large+1]=$sql["add_url"]; //URL for small sized ad banner to redirect to website
         $i++;
      }
   }

   return $ad;

}


?>

 

 

rotator.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Ad rotator test</title>
</head>

<body>

THIS IS A TEST PAGE<br /><br />

<?php require_once("ad_function.php"); ?>


<?php $ad=ads(); 



?>
<br /><br />
<a href="<?php echo $ad['url']['0']; ?>"><img src="<?php echo $ad['ad']['0']; ?>"></img></a><br />
<a href="<?php echo $ad['url']['1']; ?>"><img src="<?php echo $ad['ad']['1']; ?>"></img></a><br />
<a href="<?php echo $ad['url']['2']; ?>"><img src="<?php echo $ad['ad']['2']; ?>"></img></a><br />
<a href="<?php echo $ad['url']['3']; ?>"><img src="<?php echo $ad['ad']['3']; ?>"></img></a><br />
<a href="<?php echo $ad['url']['4']; ?>"><img src="<?php echo $ad['ad']['4']; ?>"></img></a><br />
<a href="<?php echo $ad['url']['5']; ?>"><img src="<?php echo $ad['ad']['5']; ?>"></img></a><br />
<a href="<?php echo $ad['url']['6']; ?>"><img src="<?php echo $ad['ad']['6']; ?>"></img></a><br />
<a href="<?php echo $ad['url']['7']; ?>"><img src="<?php echo $ad['ad']['7']; ?>"></img></a><br />

</body>
</html>

 

Thanks many times over, to the kind person who has helped me on this, and also to the person who chipped in with an alternative, which is also worth a look for people trying to run ads.

 

Peace!!!

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.