Announcements

The New PHP-Fusion USA
by NetriX - 4 weeks ago
Free Hosting
by NetriX - 2 months ago

Latest Posts

MySql?
by daimonbok - 15 hours ago
Video Infusion 3.2.0
by NetriX - 20 hours ago
Version 9 with php 7
by daimonbok - 7 days ago
Facebook Connect 3.0.0
by daimonbok - 1 week ago
URL shortening in PHP
by jim09 - 1 week ago
PHP-Fusion 9 Extensive Demo
by NetriX - 1 week ago
[FORUM RANKS] Flat
by Homdax - 4 weeks ago
The New PHP-Fusion USA
by NetriX - 4 weeks ago
[GUIDE] Optimize PHP-Fusion Website
by NetriX - 4 weeks ago
[FORUM RANKS] ForumCore
by NetriX - 4 weeks ago

View Thread

Who is here? 1 guest(s)
 Print Thread
Banner rotator
Dzonson
As the name says, this is a banner rotator made ??in php and html.

We create two files php and css

The first is the php file (Save to reklamy.php)
Download source  Code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
      <meta name="robots" content="none"/>

      <link rel="stylesheet" type="text/css" href="style.css"/>
   </head>
   <body>
<?php
   $reklama[] = '<a href="http://www.nfszone.pl" target="_blank"><img src="http://host.nfszone.pl/images/15265212066509942356.png" alt="NFSZone.pl - Twoje centrum NFS w Polsce" width="468" height="60" border="0"></a>';
   
      
   $reklama[] = '<a href="http://www.e-nfs.eu/" title="e-NFS.eu - Need for Speed, Shift, Nitro, World Online, Undercover, ProStreet, Carbon, Most Wanted, Underground 2, Underground" target="_blank"> <img src="http://www.e-nfs.eu/buttons/eNFSeu_468x60_01.jpg" alt="e-NFS.eu - Need for Speed, Shift, Nitro, World Online, Undercover, ProStreet, Carbon, Most Wanted, Underground 2, Underground" style="border:none;" /> </a>';
   
   
   
   $reklama[] = '<a href="http://www.needforspeed.pl" target="_blank" title="nfs, need for speed, shift, world online, nitro, undercover"><img src="http://www.tkk.pl/~bryg/baner04.gif" alt="nfs, need for speed, shift, world online, nitro, undercover" border="0"></a>';
   
      
   
   
   echo $reklama[rand(0,count($reklama)-1)];
?>
   </body>
</html>





The second image is a style (Save to styler.css)
Download source  Code
*{
   padding:0;
   margin:0;
}

body{
   text-align:center;
}

img{
   border:solid 1px #000;
}

img:hover{
   border-color:#f00;
}




All put in the same directory with the name reklamy.

[fpnotice=info]I would recommend the application includes[/fpnotice]
Edited by Dzonson on 04-10-2013 23:28
 
daimonbok
Using this in PHPFusion 9 and works fine with php 7
 
blisswebsolution
This banner rotator is a little bit different from others, the banner will change only ones a day. I used the PHP function rand() because I think that MySQL’s “ORDER BY RAND()” and the PHP function array_rand() are only a second choice.

<?php
$db = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
// create table for the banners
$db->query("
CREATE TABLE IF NOT EXISTS `banners` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(35) NOT NULL default '',
`link` varchar(150) NOT NULL default '',
`alt_title` varchar(100) NOT NULL default '',
`image` varchar(35) NOT NULL default '',
`ins_date` date NOT NULL default '0000-00-00',
`status` enum('on','off'Wink NOT NULL default 'on',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1"Wink;
// create the table for storing todays banner id
$db->query("
CREATE TABLE `rand_banner` (
`id` int(11) NOT NULL auto_increment,
`date` date NOT NULL default '0000-00-00',
`todays_id` int(11) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1"Wink;
// first check if todays banner id is already stored
$check_today_sql = "SELECT todays_id FROM rand_banner WHERE date = NOW()";
$check_today_res = $db->query($check_today_sql);
if ($check_today_res->num_rows) > 0) {
$today = $check_today_res->fetch_object();
$id_today = $today->todays_id;
} else {
// if not select a random id and store the id in the table with current date
$get_ids_sql = "SELECT id FROM banners WHERE status = 'on'";
$get_ids_res = $db->query($get_ids_sql);
$get_ids_array = array();
while ($get_ids = $get_ids_res->fetch_object()) {
$get_ids_array[] = $get_ids->id;
}
$num = count($get_ids_array);
// I use the function rand() because other random functions are not "really random"
$rand_num = rand(0, $num-1);
$id_today = $get_ids_array[$rand_num];
$db->query("INSERT INTO rand_banner (id, date, todays_id) VALUES (NULL, NOW(), $id_today)"Wink;
}
// at least select the record with the todays ID
$result = $db->query("SELECT link AS url, alt_title, image FROM banners WHERE id = $id_today"Wink;
$obj = $result->fetch_object();
// this example will show the current banner
echo "<a href=\"".$obj->url."\"><img src=\"/images/banners/".$obj->image."\" alt=\"".$obj->alt_title."\" border=\"0\"></a>";
 
daimonbok
Wasn't interested in using mysql :-), BUT can you edit this again and use the code function so all the smilel faces don't appear :-) This way those that want it can use it...
 
Jump to Forum:

Similar Threads

Thread Forum Replies Last Post
Header Banner Issues [7.02.XX] General Development 3 12-07-2014 11:09


WE RECOMMEND THIS HOST - PHP-Fusion Hosting