How to display banner adds in other blocks as well as in header.?

Requested and Answered by Carnuke on 2004/12/12 11:34:51

How to display banner adds in other blocks as well as in header.?

Create a cutom block with the following code:

include_once XOOPS_ROOT_PATH.'/include/functions.php';
global 
$xoopsConfig;
$db =& Database::getInstance();
$bannerobject '';
$bresult $db->query("SELECT COUNT(*) FROM ".$db->prefix("banner"));
list (
$numrows) = $db->fetchRow($bresult);
if ( 
$numrows ) {
    
$numrows $numrows-1;
    
mt_srand((double)microtime()*1000000);
    
$bannum mt_rand(0$numrows);
} else {
    
$bannum 0;
}
if ( 
$numrows ) {
    
$bresult $db->query("SELECT * FROM ".$db->prefix("banner"), 1$bannum);
list (
$bid$cid$imptotal$impmade$clicks$imageurl$clickurl$date$htmlbanner$htmlcode) = $db->fetchRow($bresult);
if (
$xoopsConfig['my_ip'] == xoops_getenv('REMOTE_ADDR')) {
        
// EMPTY
    
} else {
        
$db->queryF(sprintf("UPDATE %s SET impmade = impmade+1 WHERE bid = %u"$db->prefix("banner"), $bid));
}
    
/* Check if this impression is the last one and print the banner */
    
if ( $imptotal == $impmade ) {
        
$newid $db->genId($db->prefix("bannerfinish")."_bid_seq");
        
$sql sprintf("INSERT INTO %s (bid, cid, impressions, clicks, datestart, dateend) VALUES (%u, %u, %u, %u, %u, %u)"$db->prefix("bannerfinish"), $newid$cid$impmade$clicks$datetime());
        
$db->queryF($sql);
        
$db->queryF(sprintf("DELETE FROM %s WHERE bid = %u"$db->prefix("banner"), $bid));
    }
    if (
$htmlbanner){
        
$bannerobject $htmlcode;
    }else{
    
$bannerobject '
.XOOPS_URL.'/banners.php?op=click&bid='.$bid.'" target="_blank">';
        if (
stristr($imageurl'.swf')) {
            
$bannerobject $bannerobject
                
.''
                
.'.$imageurl.'">'
                
.''
                
.'.$imageurl.'" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"; type="application/x-shockwave-flash" width="468" height="60">'
                
.''
                
.'';
        } else {
            
$bannerobject $bannerobject.'.$imageurl.'" alt="" />';
        }

        
$bannerobject $bannerobject.'
'
;
}
echo 
$bannerobject;
}
Save this with a title and as php script. Position in your Page as required. NOTE: Make sure your adds are suitably sized for the blocks you are using, or else your adds will distort and break out.

This Q&A was found on XOOPS Web Application System : https://xoops.org/modules/smartfaq/faq.php?faqid=305