I have a fairly simple one I use across a bunch of my sites. Uses a 3 table database (banners, links, sites).
Pretty easy to modify out.
Database structure
--
-- Table structure for table `banners`
--
CREATE TABLE IF NOT EXISTS `banners` (
`id` int(10) NOT NULL auto_increment,
`site` int(10) NOT NULL default '0',
`name` varchar(254) NOT NULL,
`type` char(2) NOT NULL,
`width` int(10) NOT NULL default '0',
`height` int(10) NOT NULL default '0',
`last_used` datetime NOT NULL,
`active` tinyint(4) NOT NULL default '1',
PRIMARY KEY (`id`),
KEY `last_used` (`last_used`),
KEY `width` (`width`),
KEY `height` (`height`),
KEY `site` (`site`)
) ENGINE=INNODB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1406 ;
-- --------------------------------------------------------
--
-- Table structure for table `links`
--
CREATE TABLE IF NOT EXISTS `links` (
`id` int(10) NOT NULL auto_increment,
`site` int(10) NOT NULL default '0',
`link` varchar(254) NOT NULL,
`active` tinyint(4) NOT NULL default '1',
PRIMARY KEY (`id`),
KEY `site` (`site`)
) ENGINE=INNODB DEFAULT CHARSET=latin1 AUTO_INCREMENT=83 ;
-- --------------------------------------------------------
--
-- Table structure for table `sites`
--
CREATE TABLE IF NOT EXISTS `sites` (
`id` int(10) NOT NULL auto_increment,
`sponsor` int(10) NOT NULL default '0',
`name` varchar(35) NOT NULL,
`active` tinyint(1) NOT NULL default '1',
PRIMARY KEY (`id`),
KEY `sponsor` (`sponsor`)
) ENGINE=INNODB DEFAULT CHARSET=latin1 AUTO_INCREMENT=75 ;
Actual banner rotation code
// pass ins
// Type sc=softcore, hc=hardcore
// mxw maximum width in pixels
// mxh maximum height in pixels
// mnw minimum width in pixels
// mnh minimum height in pixels
function getad($type, $mxw, $mxh, $mnw, $mnh)
{
$adbhost = "localhost";
$adbuser = "dbusername";
$adbpass = "dbpassword";
$adb = mysql_connect($adbhost, $adbuser, $adbpass);
$sql_str="select a.id, a.name, c.name as sitename, a.height, a.width, b.link ";
$sql_str .="from banners a ";
$sql_str .="inner join links b on a.site=b.site ";
$sql_str .="inner join sites c on a.site=c.id ";
$sql_str .="where a.type='" . $type . "' ";
$sql_str .="and a.width<=" . $mxw . " and a.height<=" . $mxh . " and ";
$sql_str .="a.width>=" . $mnw . " and a.height>=" . $mnh . " ";
$sql_str .="order by a.last_used limit 1";
$result=mysql_query($sql_str,$adb);
if(!$result)
{
//echo "sql prob sql=" . $sql_str . "<br>\n";
}
else
{
$banner=mysql_fetch_array($result);
echo "<a href=" . $banner['link'] . " target=_blank>";
echo "<img src=http://www.yourdomainname.com/images/" . $banner['name'] . " border=0" . ' alt="' . $banner['sitename'] . '">';
echo "</a>";
}
$sql_str="update banners set last_used=now() where id=" . $banner['id'];
$result=mysql_query($sql_str,$adb);
}
How to call it in the page.
getad('sc',480,80,350,50);
__________________
All cookies cleared!
|