Need Help to Modify Ad Rotator

Hello to all !

I need help to modify an ad rotator !

What I need is to randomize the ads placement WITHOUT repeating the same ad twice.

Here is the php script (called in page) :

[php]

<?php // Function to display random ads from a list function showRandomAD($ADnumber = 1){ // Loading the ad list into an array $adList = file('adlist.txt'); // Check the total number of ads $numberOfADs = sizeof($adList); // Initialize the random generator list($usec, $sec) = explode(' ', microtime()); srand((float) $sec + ((float) $usec * 100000)); // Initialize the ads counter $adCount = 0; // Loop to display the requeste number of ads while ($adCount++ < $ADnumber) { // Generate random ad id $actAD = rand(0, $numberOfADs-1); // Display the above generated ad from the array echo $adList[$actAD].'
'; } } ?>

[/php]

Let me know if you can help… or if it can’t be done (if so, recommendations for an ad rotator that does what I want would be great, either Javascript or PHP) !

Thanks !
Ian

Edit:

I think this is what you were going for.

[php]
function showRandomAD($ADnumber = 1) {
$adList = file(‘adlist.txt’);
shuffle($adList); // shuffle array

// loop array 
$i = 0;
foreach($adList as $key => $value) {
	if ($i === $ADnumber) {
		return; // stop incrementing array if $ADnumber is reached
	}
	$i++; // increment counter
	echo $value . "<br />"; // output
}

}
[/php]

Hello M@tt !

This is EXACTLY what I need !! :smiley:

Thank you very much, I appreciate your quick response AND great answer !

Ian

Sponsor our Newsletter | Privacy Policy | Terms of Service