Rotating TextLink Ads

Discussion in 'PHP' started by itdevil, Oct 2, 2007.

  1. #1
    Hi, I am looking to put php script on my site which show random textlink ads. I found JAB script but it currently only show 1 text link. I am looking to show 5 to 15 text adds. anyone know how can i customize it to show multiple ads or if there is free script out there which can do it, please let me know, OpenAds does not rotate the text ads

    i want the to look like

    Text0 Text1 text2 text3 text4

    <?php
    
    $option = "link";
    
    $sites[0] = array("http://www.site2.com", "Text0", 1);
    $sites[1] = array("http://www.site3.com", "Text1", 1);
    $sites[2] = array("http://www.site1.com", "Text2", 1);
    $sites[3] = array("http://www.site2.com", "Text3", 1);
    $sites[4] = array("http://www.site2.com", "Text4", 1);
    $sites[5] = array("http://www.site3.com", "Text5", 1);
    $sites[6] = array("http://www.site1.com", "Text6", 1);
    $sites[7] = array("http://www.site2.com", "Text7", 1);
    $sites[8] = array("http://www.site3.com", "Text8", 1);
    $sites[9] = array("http://www.site1.com", "Text9", 1);
    
    $countsites = count($sites);
    
    for($i=0; $i<$countsites; $i++)
    	{
    	for($x=0; $x<$sites[$i][2]; $x++)
    		{
    		if($option != null)
    			{
    			$mylist[] = array($sites[$i][0],$sites[$i][1],$sites[$i][3]);
    			}
    		else
    			{
    			echo("Error deciding option.");
    			exit();
    			}
    		}
    	}
    
    $countlist = count($mylist);
    
    $countlist = $countlist - 1;
    
    $picker = rand(0, $countlist);
    
    if($option == "link")
    	{
    	echo("<a href='" . $mylist[$picker][0] . "'>" . $mylist[$picker][1] . "</a>");
    	}
    
    else if($option == "banner")
    	{
    	echo("<a href='" . $mylist[$picker][0] . "'><img alt='" . $mylist[$picker][1] . "' src='" . $mylist[$picker][2] . "' /></a>");
    	}
    
    else
    	{
    	echo("Error deciding option.");
    	exit();
    	}
    
    //Created by James Barnsley. All rights reserved.
    
    ?>
    PHP:
    Thanks in advance
     
    itdevil, Oct 2, 2007 IP
  2. vonvhen

    vonvhen Peon

    Messages:
    152
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    one simple way is to add 4 more $picker values and then echo them

    e.g. $picker2 = rand(0, $countlist);
    echo("<a href='" . $mylist[$picker2][0] . "'>" . $mylist[$picker2][1] . "</a>");

    the only problem with this is that you might get duplicate links
     
    vonvhen, Oct 2, 2007 IP
  3. kendo1979

    kendo1979 Peon

    Messages:
    208
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    why not make it picker2 = picker1 +1 if picker2 > than countlist then picker2 = picker2 - countlist. there won't be any duplicat, if the countlist is more than 5. but it will show sequential from a first random pickup instead of all random.
     
    kendo1979, Oct 2, 2007 IP