调用方式如下:其中DebugStr这个函数就是类似一个echo。
<BR>DebugStr('$Adv->getContentById($id); $id为广告编号, 仅调用一条,返回内容为字符串'); <BR>echo Adv::getContentById(35); <BR>DebugStr('$Adv->getContentByIdJS($<mark>@本文来源gaodaimacom搞#代%码@网-</mark><strong>搞代gaodaima码</strong>id); $id为广告编号, 仅调用一条,返回内容为JS字符串'); <BR>echo Adv::getContentByIdJS(35); <BR>DebugStr('$Adv->getContentByOrder($id); $id为广告编号, 仅调用ID倒序一条,返回内容为字符串'); <BR>echo Adv::getContentByOrder(4); <BR>DebugStr('$Adv->getContentByOrderJS($id); $id为广告编号, 仅调用ID倒序一条,返回内容为JS字符串'); <BR>echo Adv::getContentByOrderJS(4); <BR>echo '<hr>'; <BR>
类如下:
<BR><?php <BR>/** <BR>* 说明:广告类,方便广告列表、内容的调用。 <BR>* 需要:数据库类 <BR>* 支持:仅支持PHP5,单件模式 <BR>* <BR>* @author Zerolone <BR>* @version 2011-1-6 11:32:06 <BR>* 调用方法 <BR>* Adv::getContentById($id); $id为广告编号, 仅调用一条,返回内容为字符串 <BR>* Adv::getContentByIdJs($id); $id为广告编号, 仅调用一条,返回内容为JS字符串 <BR>* Adv::getContentByOrder($order); $order为对应, 仅调用ID倒序一条,返回内容为字符串 <BR>* Adv::getContentByOrderJs($order); $order对应顺序, 仅调用ID倒序一条,返回内容为JS字符串 <BR>*/ <BR>class Adv { <BR>static $Id = 0; //编号 <BR>static $Order = 0; //顺序 <BR>static $JS = 0; //是否使用JS, 0为不使用 <BR>/** <BR>* 根据Id, 返回广告内容,仅调用一条 <BR>* <BR>* @param 编号 $id <BR>* <BR>*/ <BR>public static function getContentById($id){ <BR>self::$Id = $id; <BR>return self::getContent(); <BR>} <BR>/** <BR>* 根据Id, 返回广告内容Js,仅调用一条 <BR>* <BR>* @param 编号 $id <BR>* <BR>*/ <BR>public static function getContentByIdJS($id){ <BR>self::$Id = $id; <BR>self::$JS = 1; <BR>return self::getContent(); <BR>} <BR>/** <BR>* 根据Order, 返回广告内容,仅调用一条 <BR>* <BR>* @param 编号 $Order <BR>* <BR>*/ <BR>public static function getContentByOrder($order){ <BR>self::$Order = $order; <BR>return self::getContent(); <BR>} <BR>/** <BR>* 根据Order, 返回广告内容Js,仅调用一条 <BR>* <BR>* @param 编号 $Order <BR>* <BR>*/ <BR>public static function getContentByOrderJS($order){ <BR>self::$Order = $order; <BR>self::$JS = 1; <BR>return self::getContent(); <BR>} <BR>/** <BR>* 生成一个广告内容,只调用一条 <BR>* <BR>* @return 广告内容 <BR>*/ <BR>private function getContent(){ <BR>$ReturnContent=''; <BR>//------------------0-------1--------2--------3 <BR>$SqlStr = 'SELECT `pic`, `width`, `height`, `url` FROM '.TABLE_ADV; <BR>if(self::$Id){ <BR>$SqlStr.= ' WHERE `id`=' . self::$Id; <BR>}else{ <BR>$SqlStr.= ' WHERE `order`=' . self::$Order; <BR>$SqlStr.= ' ORDER BY `id` DESC '; <BR>} <BR>$SqlStr.= ' LIMIT 1'; <BR>$MyDatabase=Database::Get(); <BR>$MyDatabase->SqlStr = $SqlStr; <BR>if ($MyDatabase->Query ()) { <BR>$DB_Record = $MyDatabase->ResultArr [0]; <BR>$FileName = $DB_Record[0]; <BR>$Width = $DB_Record[1]; <BR>$Height = $DB_Record[2]; <BR>$Url = $DB_Record[3]; <BR>} <BR>//判断类型 <BR>$FileName_Ext=strtoupper(pathinfo($FileName, PATHINFO_EXTENSION)); <BR>if ($FileName_Ext=='SWF'){ <BR>//Flash广告 <BR>$ReturnContent = '<table width="' . $Width .'" border="0" cellspacing="0" cellpadding="0">'; <BR>$ReturnContent.= '<tr>'; <BR>$ReturnContent.= '<td height="' . $Height . '">'; <BR>$ReturnContent.= '<table width="100%" border="0" cellpadding="0" cellspacing="0">'; <BR>$ReturnContent.= '<tr>'; <BR>$ReturnContent.= '<td>'; <BR>$ReturnContent.= '<div style="width:0px;height:0px">'; <BR>$ReturnContent.= '<div>'; <BR>$ReturnContent.= '<table width="100%" border="0" cellspacing="0" cellpadding="0">'; <BR>$ReturnContent.= '<tr>'; <BR>$ReturnContent.= '<td style="cursor:hand"> </td>'; <BR>$ReturnContent.= '</tr>'; <BR>$ReturnContent.= '</table>'; <BR>$ReturnContent.= '
‘;
$ReturnContent.= ‘