spikypunker Posted December 5, 2008 Author Share Posted December 5, 2008 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!!! Quote Link to comment https://forums.phpfreaks.com/topic/135309-solved-php-ad-rotator/page/2/#findComment-706660 Share on other sites More sharing options...
GKWelding Posted December 5, 2008 Share Posted December 5, 2008 No problem mate. Glad it works for you. Enjoy. Quote Link to comment https://forums.phpfreaks.com/topic/135309-solved-php-ad-rotator/page/2/#findComment-706820 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.