PDA

View Full Version : Good Rotating Ad Script in PHP



Doug
04-19-2006, 09:58 AM
Does anyone have the php script to make rotating skyscraper ads. I want my ads to rotate every few seconds but all the script I find either isn't what I want or doesn't work right. PHP works fine on my website too so that isn't the problem.

Emancipator
04-19-2006, 10:32 AM
you cant do that with php alone. You can do it with xmlhttp and php, but its far easier to do it with javascript.

Doug
04-19-2006, 11:45 AM
Do you know the script I would need to do it with javascript or is it fairly easy to find with a google search.

Emancipator
04-19-2006, 12:01 PM
fairly easy to find with google i am sure. I wrote my own.

Giles
04-20-2006, 01:42 AM
http://hotscripts.com

go to the php section and then ad management

Emancipator
04-20-2006, 05:49 AM
giles php cant do what hes asking for. you can do it with php and xmlhttp or javascript but NOT php alone.

Giles
04-20-2006, 05:12 PM
I've been to sites where you just add all your ad codes and then paste an iframe onto your site and the ads roatate.

Todd W
04-20-2006, 08:46 PM
www.adpeeps.com works awesome :D

Emancipator
04-20-2006, 08:54 PM
so with php and an iframe how are you making it rotate ever 5seconds with pure php? I have never been able to do it and would love to hear how. Always willing to admit I am wrong and learn something new. I have never been able to do it with php scripting on its own ( no cron, no xmlhttp and no jscript )

Giles
04-20-2006, 09:09 PM
I'm not sure how, I used to have roatating amazon ads, i'll see if i can find the script.

EDIT: I just tested it and it turns out that the ads rotate on every reload. Sorry.

Emancipator
04-21-2006, 06:09 AM
No worries. I knew that would be the answer once you looked. I just wanted to give the benefit of the doubt that I somehow missed a huge part of php. I have been working on an MMORPG in php for some time and have had to do alot of xmlhttp work to get it work in "real time".

Updating every few seconds is easily done just not with php alone :)

keith1764
09-23-2009, 02:28 AM
I'm new to php so I'm sure this could be buggy as h*ll in some implementations, but if you want to rotate ads in multiple zones with only one ad per affiliate, here's what I've done. It works for me:

<?php
require $docroot."Config/db_config.php";
$connection = @mysql_connect ($db_host, $db_user, $db_password) or die("error connecting");
mysql_select_db ($db_name, $connection);
$query = mysql_query("SELECT ad_no FROM siteads") or die(mysql_error());
$result = ($query);
$adsInDB = mysql_num_rows($result);
$ad_no = array();
for ($i = 0; $i < mysql_num_rows($result); $i++)
{
$ad_number = mysql_result($result, $i, "ad_no");
array_push($ad_no, $ad_number);
}
$adsToPrint = 1;
$ad = array();
$affiliate_done = array();
$zoneCounter = 0;

// Add advertisement types here
$zoneCounter++;
$adType[$zoneCounter] = "text"; //zone 1
$zoneCounter++;
$adType[$zoneCounter] = "text"; //zone 2
$zoneCounter++;
$adType[$zoneCounter] = "sml_bnr"; //zone 3
$zoneCounter++;
$adType[$zoneCounter] = "lrg_scrpr"; //zone 4
$zoneCounter++;
$adType[$zoneCounter] = "lrg_scrpr"; //zone 5
$zoneCounter++;
$adType[$zoneCounter] = "sml_box"; //zone 6
$zoneCounter++ ;
$adType[$zoneCounter] = "sml_box"; //zone 7
$zoneCounter++;
$adType[$zoneCounter] = "sml_box"; //zone 8
$zoneCounter++;
$adType[$zoneCounter] = "sml_box"; //zone 9
$zoneCounter++;
$adType[$zoneCounter] = "sml_box"; //zone 10
$zoneCounter++;
$adType[$zoneCounter] = "lrg_scrpr"; //zone 11
$zoneCounter++;
$adType[$zoneCounter] = "lrg_bnr"; //zone 12

if ($zoneCounter > $adsInDB)
{
$zoneCounter = $adsInDB;
}

while ($adsToPrint <= $zoneCounter)
{
//Pick a random ad
$adPicked = rand(1,$adsInDB);
if ($adPicked <1)
{
$adPicked = 1;
}
$i = 0;
while ($i != 5)
{
if (in_array($adPicked, $ad_no))
{
$i = 5;
}
else
{
if ($adPicked >= $adsInDB/2)
{
$adPicked--;
}
$adPicked++;
}
}
$adPicked = (int)$adPicked;
$query = mysql_query("SELECT * FROM siteads WHERE ad_no = $adPicked") or die(mysql_error());
$result = ($query);
$row = mysql_fetch_array($result);
if (empty($ad[$adsToPrint]))
{
if (in_array($row["affiliate"], $affiliate_done))
{}
else
{
if ($row["type"] == $adType [$adsToPrint])
{
$ad[$adsToPrint] = $row["code"];
$adsToPrint++;
array_push($affiliate_done, $row["affiliate"]);
}
}
}
}
?>

Just include this file and replace your ads with <?php $ad[1]?>, <?php $ad[2]?>. <?php $ad[3]?>, ect.

Hope that helps.

Mr. Pink
09-23-2009, 08:30 AM
Keith,

First of all, thank you... but...

...what are the exact instructions?

We have to include this file where? Place it into the public_html folder?

What should this file be called?

Is there are tag that needs to be placed on every page where the ads should appear?

And what does this mean? "...replace your ads with <?php $ad[1]?>, <?php $ad[2]?>. <?php $ad[3]?>, ect."

thanks...