Jump to content
xisto Community
Sign in to follow this  
FaLgoR

Rotate Banner Rotate Banner with PHP + MYSQL

Recommended Posts

Well, this topic is for you that wants to have a rotate banner in your site.

First, create a new table on mysql:

CREATE TABLE `banners` (
`id` BIGINT( 255 ) NOT NULL AUTO_INCREMENT ,
`imageurl` VARCHAR( 255 ) NOT NULL ,
`alt` VARCHAR( 255 ) NOT NULL ,
`url` VARCHAR( 255 ) NOT NULL ,
`clicks` BIGINT( 255 ) NOT NULL ,
PRIMARY KEY ( `id` )
);

well, now lets insert a new banner on this table:

INSERT INTO `banners` ( `id` , `imageurl` , `alt` , `url` , `clicks` )
VALUES (
'', 'http://forums.xisto.com/no_longer_exists/' 'Xisto - The best free web hosting on the web', 'http://forums.xisto.com/' ''
);

Now, the page which will show the banners:

<?
mysql_connect("localhost","user","pass");
mysql_select_db("dbname");
$randbanner = mysql_query("SELECT * FROM banners ORDER BY RAND() LIMIT 1");
$i = 1;
while($banner = mysql_fetch_array($randbanner)){
$id = $banner["id"];
$imageurl = $banner["imageurl"];
$alt = $banner["alt"];
$url = $banner["url"];
$clicks = $banner["clicks"];

$banners[$i]"http://forums.xisto.com/= "$imageurl";
$banners[$i]http://forums.xisto.com/= "click.php?id=$id";
$banners[$i][alt] = "$alt";

$r = rand($i,sizeof($banners)); // rotate

echo '<a href="'.$banners[$r]." target="_blank"><img src="'.$banners[$r]"" alt="'.$banners[$r][alt].'" border="0"></a>'; // Show the banner
}
?>

Now, lets make clicks.php:

<?
mysql_connect("localhost","user","pass");
mysql_select_db("dbname");
$id = addslashes($_GET['id']); // addslashes is for security of your database
$clicks = mysql_query("UPDATE banners SET clicks=clicks+1 WHERE id='$id'");
$table = mysql_query("SELECT * FROM banners WHERE id='$id'");

$details=mysql_fetch_array($table);

$url = $details["url"];
$id = $details["id"];

echo '<meta http-equiv="refresh" content="1;url='.$url.'">'; // After 1 second, redirect for the URL of the banner
?>

That's all, if you have any questions just post here! :rolleyes:



Share this post


Link to post
Share on other sites

Hey thanks I've been looking for this for a while. I have tried another one. But that one was javascript. The result was that on some of my friends' browsers the didn't work becuase they had javascript disabled. This one is php right? BTW I can't read PHP so I don't know what it does. But this is supposed to make a new banner everytime you load the page right?

Share this post


Link to post
Share on other sites

The script is fine. Members who have a very large site ( especially sites ) can use PHPADSNEW for rotating and managing ads. It does the same work and it is very powerful. Provides great tools and options for targetting and managing the ad campigns. Xisto members can install it with a single click ( included in fantastico )- OpaQue.

Share this post


Link to post
Share on other sites

I don't know about the scripts installed here, but im just tring to help who wants to make their own. If everybody only uses scripts already installed they will got some dependance of them.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.