調用方式如下:其中DebugStr這個函數就是類似一個echo。
複製代碼 代碼如下:
DebugStr('$Adv->getContentById($id); $id為廣告編號, 僅調用一條,返回內容為字串');
echo Adv::getContentById(35);
DebugStr('$Adv->getContentByIdJS($id); $id為廣告編號, 僅調用一條,返回內容為JS字串');
echo Adv::getContentByIdJS(35);
DebugStr('$Adv->getContentByOrder($id); $id為廣告編號, 僅調用ID倒序一條,返回內容為字串');
echo Adv::getContentByOrder(4);
DebugStr('$Adv->getContentByOrderJS($id); $id為廣告編號, 僅調用ID倒序一條,返回內容為JS字串');
echo Adv::getContentByOrderJS(4);
echo '';
類如下:
複製代碼 代碼如下:
/**
* 說明:廣告類,方便廣告列表、內容的調用。
* 需要:資料庫類
* 支援:僅支援PHP5,單件模式
*
* @author Zerolone
* @version 2011-1-6 11:32:06
* 調用方法
* Adv::getContentById($id); $id為廣告編號, 僅調用一條,返回內容為字串
* Adv::getContentByIdJs($id); $id為廣告編號, 僅調用一條,返回內容為JS字串
* Adv::getContentByOrder($order); $order為對應, 僅調用ID倒序一條,返回內容為字串
* Adv::getContentByOrderJs($order); $order對應順序, 僅調用ID倒序一條,返回內容為JS字串
*/
class Adv {
static $Id = 0; //編號
static $Order = 0; //順序
static $JS = 0; //是否使用JS, 0為不使用
/**
* 根據Id, 返回廣告內容,僅調用一條
*
* @param 編號 $id
*
*/
public static function getContentById($id){
self::$Id = $id;
return self::getContent();
}
/**
* 根據Id, 返回廣告內容Js,僅調用一條
*
* @param 編號 $id
*
*/
public static function getContentByIdJS($id){
self::$Id = $id;
self::$JS = 1;
return self::getContent();
}
/**
* 根據Order, 返回廣告內容,僅調用一條
*
* @param 編號 $Order
*
*/
public static function getContentByOrder($order){
self::$Order = $order;
return self::getContent();
}
/**
* 根據Order, 返回廣告內容Js,僅調用一條
*
* @param 編號 $Order
*
*/
public static function getContentByOrderJS($order){
self::$Order = $order;
self::$JS = 1;
return self::getContent();
}
/**
* 產生一個廣告內容,只調用一條
*
* @return 廣告內容
*/
private function getContent(){
$ReturnContent='';
//------------------0-------1--------2--------3
$SqlStr = 'SELECT `pic`, `width`, `height`, `url` FROM '.TABLE_ADV;
if(self::$Id){
$SqlStr.= ' WHERE `id`=' . self::$Id;
}else{
$SqlStr.= ' WHERE `order`=' . self::$Order;
$SqlStr.= ' ORDER BY `id` DESC ';
}
$SqlStr.= ' LIMIT 1';
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query ()) {
$DB_Record = $MyDatabase->ResultArr [0];
$FileName = $DB_Record[0];
$Width = $DB_Record[1];
$Height = $DB_Record[2];
$Url = $DB_Record[3];
}
//判斷類型
$FileName_Ext=strtoupper(pathinfo($FileName, PATHINFO_EXTENSION));
if ($FileName_Ext=='SWF'){
//Flash廣告
$ReturnContent = '
'; $ReturnContent.= '
'; $ReturnContent.= '
'; $ReturnContent.= '
'; $ReturnContent.= '
'; $ReturnContent.= '
'; $ReturnContent.= ''; $ReturnContent.= ''; $ReturnContent.= '
'; $ReturnContent.= '
'; $ReturnContent.= '
| | '; $ReturnContent.= '
'; $ReturnContent.= '
'; $ReturnContent.= ''; $ReturnContent.= ''; $ReturnContent.= ''; $ReturnContent.= ''; $ReturnContent.= ''; $ReturnContent.= ''; $ReturnContent.= ''; $ReturnContent.= ' | '; $ReturnContent.= '
'; $ReturnContent.= '
'; $ReturnContent.= ' | '; $ReturnContent.= '
'; $ReturnContent.= '
';
}else{
//圖片廣告
$ReturnContent = '';
}
//如果為調用JS方式
if(self::$JS){
$ReturnContent = 'document.write("'.addslashes($ReturnContent).'");';
}
//重設預設值,這裡還是採用單件模式
self::$Id = 0;
self::$Order = 0;
self::$JS = 0;
return $ReturnContent;
}
}
?>
http://www.bkjia.com/PHPjc/324181.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/324181.htmlTechArticle調用方式如下:其中DebugStr這個函數就是類似一個echo。 複製代碼 代碼如下: DebugStr('$Adv-getContentById($id); $id為廣告編號, 僅調用一條,返回內...