Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Randomised Ads

Very true.  I just editted my random ad system to work with my database, and I started that with 1 because, the way it's programmed, starting it with zero can produce an error.  So, there are some cases where starting at another number is ok, but in most cases you should stick with 0.
 
...Simpler than AbyssalLord's (I just modified it, so credit goes to him/her)

Code:
<?php
//The multidimentional array containing all of the ad info - this is the only place you edit
$ads = array(   
//               Image Source        Hyperlink Destination          Alt Text
0 => array('images/ad1.png', 'http://www.yoursite.com', 'My Awesome Site'),
1 => array('images/ad2.png', 'http://www.anothersite.net', 'Another Site') //...so on, so forth
);

//-------------------There's no need to edit anything beneath this point------------------------

//select a random ad from the array
$select = rand(1, count($ads) + 1);

//display the selected ad
echo '<a href="'.$ads[$select][1].'"><img src="'.$ads[$select][0].'" alt="'.$ads[$select][2].'" /></a>';

?>
 

___

Sponsor

Ah that's the beauty of open source, there's always a way to make it better and always someone who knows how to do it :D
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top