Banner rotator code using PHP/MYSQL

Banner rotator code using PHP/MYSQL
FREE BANNER ROTATOR CODE
Many of my friends from faucet owner lobby are asking for a simple and effective code for banner rotator which they can use anywhere they want. So i came to conclusion with these codes. And i found them simple and effective.
Click To Check Simple Banner Rotator Code Without MYSQL
LEARN HOW TO MAKE FREE PHP MYSQL BANNER ROTATOR
First make an sql table in your existing database, or if u are not using any database then first create database and then run this query in SQL tab of phpmyadmin.
CREATE TABLE `banners` ( `id` int(50) NOT NULL AUTO_INCREMENT, `code` text NOT NULL, `status` int(5) NOT NULL, `size` varchar(150) NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Ad this form code where ever u want backend to be available. This form will add banners and codes to your database. Add css styling by yourself as this change with every template. I am providing only form code.
<!-- FORM TO ADD BANNER --> <form action="" method="post"> <input type="text" name="adsize" placeholder="Size of the Banner" required /><br /> <textarea name="adcode" placeholder="Advertisement Code" required></textarea><br /> <input type="radio" name="status" value="1"/>Enable | <input type="radio" name="status" value="2"/>Disable <br /> <input type="submit" value="Submit" name="bannerform" /> </form> <!-- FORM TO ADD BANNER -->
Add this line in same page where banner HTML form is available. This code will connect Form with Database and register your advertisement code into it.
<?php #ADD BANNER TO DATABASE# if(isset($_POST['bannerform'])){ $advertsize = trim($_POST['adsize']); $advertcode = trim($_POST['adcode']); $status = trim($_POST['status']); if(empty($_POST['adsize']) OR empty($_POST['adcode'])) { echo 'Sorry required field left empty'; } else { $advertcode = base64_encode($advertcode); $sql = "INSERT into `banners` (code,status,size) VALUES ('$advertcode','$status','$advertsize')"; $result = $dbcon -> query($sql); if(!empty($result)) { echo 'Advertisement successfully registerd'; } else { echo 'Failed to register'; } } } #ADD BANNER TO DATABASE# ?>
Add this function in you existing function.php file or if there is none. Then make a function.php file and add this code make sure to use it with <?php and ?> tags because this is php function. And add that page to the page where you want to display Banner rotator.
#FUNCTION FOR BANNER ROTATOR# function bannerRot($size){ global $dbcon; $sql = "SELECT `code` FROM `banners` WHERE `size` = '$size' AND `status` = 1 ORDER BY RAND() LIMIT 1"; $result = $dbcon -> query($sql); if(mysqli_num_rows($result) > 0){ $row = $result -> fetch_assoc(); return base64_decode($row['code']); } } #FUNCTION FOR BANNER ROTATOR#
This step is for those who have no existing Database connection page. Make a connection page and write this code into it and change details.
#CONNECTION WITH MYSQL# $dbcon = new mysqli('localhost','root','databasepassword','test_rotator'); #CONNECTION WITH MYSQL#
Use <?php echo bannerRot(‘468×60’); ?> wherever you want to display 468×60 size banners.
Hi friends, good post and good arguments commented at this place, I am truly enjoying by
these.
Hi, Your codes are easy and good. Working.
Simple and easy banner rotator code. Thank you