• View our reviews on Hot Scripts
  • JS Tutorial

Recent Comments

Powered by Disqus

Back to articles

Random banner rotation in ptcevolution script

Here is a way to implement random banner rotation to show multiple random banners on same page. This script works for  PTC Evolution Version 1.1.0 script. Didn't test it on other versions. For more information about script visit PTC Evolution website.

So what you'll need to do is to create banners.php file in your root directory with code below:


//output content as javascript
header("content-type: application/x-javascript");

//including your site settings

//database connection
$con = mysql_connect($db_server, $db_user, $db_passwd) or die (mysql_error());
mysql_select_db($db_name, $con) or die (mysql_error());

//getting random row
$query = "SELECT FLOOR(RAND() * COUNT(*)) AS random_row FROM banner_ads ".
        "WHERE status = 'Active' and credits > 0";
$result = mysql_query($query, $con) or die (mysql_error());

//if there is any row
if(mysql_num_rows($result) > 0)

    $row = mysql_fetch_array($result) or die (mysql_error());

    //getting banner from random row
    $query = "SELECT id, img, credits, views FROM banner_ads ".
            "WHERE status = 'Active' and credits > 0 LIMIT ".$row['random_row'].", 1";
    $result = mysql_query($query, $con) or die (mysql_error());
    $row = mysql_fetch_array($result) or die (mysql_error());

    //updateing banner impressions and views
    $query = "UPDATE banner_ads SET credits = '".($row['credits'] - 1)."', ".
            "views = '".($row['views'] + 1)."' WHERE ID = '".$row['id']."'";
    $result = mysql_query($query, $con) or die (mysql_error());
    //outputting banner
    echo "document.write('<a href="bannerclick.php?id=".$row['id']."" ".
        "target="_blank"><img src="".$row['img']."" border="0" ".
        "width="468" height="60"></a>');";

Then you'll just need to modify your template files by inserting this code anywhere, where you want random banner to appear:

{if empty($banner)}
    <a href="index.php?view=advertise">
        <img src="templates/{$template_name}/images/ad_468x60.jpg" border="0">
    <script type="text/javascript" src="banners.php"></script>

As in random, there is still a probability that same banner from same advertiser might appear on same page more than once, but the more banners you have in rotation, the lesser is that probability

You may also be interested in:

Powered by

blog comments powered by Disqus