Forum Moderators: coopster

Message Too Old, No Replies

Can Somebody Show Me How To Do A Rotating Banner Script with php

         

naitsirhc26

6:17 pm on Jun 27, 2006 (gmt 0)

10+ Year Member



Please just write down all of the code, and how to do the database. This is all really confusing. Thanks.

naitsirhc26

6:31 pm on Jun 27, 2006 (gmt 0)

10+ Year Member



Is there any way for me not to have to use a database. If you could write the code, then i could fill in the blanks with my banners. Thank you so much.

eelixduppy

6:32 pm on Jun 27, 2006 (gmt 0)



Well I'm not sure exactly what you are getting from the database, but the script could look something like this:


$content = array("page1.html","page2.html","page3.html");
[url=http://us2.php.net/manual/en/function.shuffle.php]shuffle[/url]($content);
echo [url=http://us2.php.net/manual/en/function.file-get-contents.php]file_get_contents[/url]($content[0]);

Hope this helps. Good luck!

naitsirhc26

7:36 pm on Jun 27, 2006 (gmt 0)

10+ Year Member



I was wondering if anybody could write both codes for me. I don't have a database and I don't know what a database is but if you could write all of the code that would be great.

dreamcatcher

8:57 pm on Jun 27, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



naitsirhc26, we are here to help you in anyway we can to help yourself. There are some very knowledgeable guys here who take time out from their day to day jobs to answer questions such as your own. As such, I would ask you respect that simply requesting someone to write a code dump may never happen.

We try and encourage you to write your own code, which is far better from a learning curve. Post what you have and we will try and help.

dc

naitsirhc26

1:02 am on Jun 28, 2006 (gmt 0)

10+ Year Member



I am very sorry, how about this:

ad_rotation.php or should I name it ad_rotation.html?

$bannerCounter= 1;

$bannerCode[$bannerCounter] = "<a href=\"http://example.com/categories.php?PARTNER=unstabletable\"><img src=\"http://unstabletable.example.net/affiliate/ad05.jpg\" border=\"0\"></a>";
$bannerCounter++;

$bannerCode[$bannerCounter] = "<a href=\"http://www.example.com/redir.php?aff=8073\"><img src=\"http://unstabletable.example.net/affiliate/hp_ad.gif\" border=\"0\"></a>";
$bannerCounter++;

$bannerAdTotals = $bannerCounter - 1;
if($bannerAdTotals>1)
{
mt_srand((double)microtime() * 1234567);
$bannerPicked = mt_rand(1, $bannerAdTotals);
}
else
{
$bannerPicked = 1;
}
$bannerAd = $bannerCode[$bannerPicked];

Place where I want that code placed:

<?
include("ad_rotation.php");
echo "<div align='center'>$bannerAd</div>";
?>

eelixduppy

1:09 am on Jun 28, 2006 (gmt 0)



;) Glad that you decided to try to make the script yourself. Just so that you can see how to incorporate my example, it would go something like this:


$content = array(
"<a href=\"http://example.com/categories.php?PARTNER=unstabletable\"><img src=\"http://unstabletable.example.net/affiliate/ad05.jpg\" border=\"0\"></a>",
"<a href=\"http://www.example.com/redir.php?aff=8073\"><img src=\"http://unstabletable.example.net/affiliate/hp_ad.gif\" border=\"0\"></a>"
);
shuffle($content);
echo $content[0];

Best of luck!

P.S. ad_rotation.php is what you want ;)

[edited by: eelixduppy at 1:10 am (utc) on June 28, 2006]

naitsirhc26

1:10 am on Jun 28, 2006 (gmt 0)

10+ Year Member



Okay I have this one, sorry, scratch the other one:

This is the code I use to place my banners:

<?
include("ad_rotator.php");
echo "<div align='center'>$bannerAd</div>";
?>

This is the code I use on ad_rotator.php

$bannerCounter= 1;

$bannerCode[$bannerCounter] = "<a href=\"http://www.example.com/advertise.php\"><img src=\"images/youradherebig.gif\" border=\"0\"></a>";
$bannerCounter++;

$bannerCode[$bannerCounter] = "<a href=\"http://www.example.com/advertise.php\"><img src=\"images/youradhere.gif\" border=\"0\"></a>";
$bannerCounter++;

$bannerAdTotals = $bannerCounter - 1;
if($bannerAdTotals>1)
{
mt_srand((double)microtime() * 1234567);
$bannerPicked = mt_rand(1, $bannerAdTotals);
}
else
{
$bannerPicked = 1;
}
$bannerAd = $bannerCode[$bannerPicked];

Why isn't it working? I can't figure it out. I am not using a database or anything, what am I doing wrong? Please help.

[edited by: coopster at 12:58 pm (utc) on June 28, 2006]
[edit reason] generalized domain [/edit]

naitsirhc26

2:19 am on Jun 28, 2006 (gmt 0)

10+ Year Member



Well, I tried this:

$content = array(
"<a href=\"http://www.example.com\"><img src=\"youradherebig.gif\" border=\"0\"></a>",
"<a href=\"http://www.example.com\"><img src=\"youradhere.gif\" border=\"0\"></a>"
);
shuffle($content);
echo $content[0];

But it still won't work. Do you see any mistakes?

[edited by: coopster at 12:58 pm (utc) on June 28, 2006]
[edit reason] generalized domain [/edit]

eelixduppy

2:34 am on Jun 28, 2006 (gmt 0)



The code you posted works for me. Try adding error_reporting(E_ALL); to the top of the script to see if any errors are occuring.

naitsirhc26

5:08 pm on Jun 28, 2006 (gmt 0)

10+ Year Member



Thanks for the help, I think I can get it to work.