0 Comments

显示广告列表(1)

发布于:2012-11-26  |   作者:广州网站建设  |   已聚集:人围观

  显示广告列表(1)

广告管理程序的核心是广告页面展示的部分,它的作用相对一个引导页面所有的操作,都是从看到广告列表的显示开始发起的。首先来看页面列表显示部分的程序实现,代码如下:

广州网站设计
  1. /*******************************************  
  2. '文件名:index.php  
  3. '主要功能:广告管理模块index  
  4. '说明:  
  5. '*******************************************/  
  6. include_once(dirname(__FILE__)."/inc/include.smarty.php");    
  7.                                                     //加载Smarty配置文件  
  8. include(dirname(__FILE__). "/inc/include.function.php");    //加载函数库文件  
  9. require(dirname(__FILE__)."/config/config.php");            //加载容配置文件  
  10. $type=$_REQUEST[type];                                      //获得操作类型  
  11. $kw=$_REQUEST[kw];  
  12. $page=$_REQUEST[page];                                      //获得当前页数  
  13. if($page<1){  
  14.     $page=1;  
  15. }  
  16. $page=$page-1;  
  17. $msgd=explode("|www_allen|",file_get_contents($dbtable));   //切割字符串  
  18. $rows=count($msgd);                                         //计算行数  
  19. if($kw){  
  20. for ($i=0;$i<=$rows;$i++){  
  21.     $tmp2=explode("|allen|",$msgd[$i]);  
  22.     if($type=="name"){                                  //判断操作类型(name)  
  23.         $msgn[$i]=$tmp2[0];  
  24.         }elseif($type=="nr"){  
  25.             $msgn[$i]=$tmp2[2];  
  26.         }  
  27.         elseif($type=="gge"){                           //类型判断(gge)  
  28.             $msgn[$i]=$tmp2[4];  
  29.         }  
  30.     else{$msgn[$i]=$tmp2[3];  
  31. }  
  32. if(eregi($kw,$msgn[$i])){                               //字符串比对解析  
  33.     $chj_nr[]=$msgd[$i];  
  34.     $chj_numib++;  
  35.     }  
  36. }  
  37. if($chj_numib<1){  
  38.     echo "没有相关 $kw 的匹配结果!!";                        //输出报错信息  
  39.     exit;  
  40. }  
  41. $msg=array_reverse($chj_nr);  
  42.     $total=ceil($chj_numib/$pagesize);                  //计算总页面数  
  43.     $kwnum=-1;  
  44.     }else{  
  45.         $chj_numib=$rows;  
  46.         $msg=array_reverse($msgd);  
  47.     $total=ceil($chj_numib/$pagesize);                  //计算分页  
  48.     }  
  49. //如果每页显示数*总页数小于留言总条数则  
  50. if($pagesize*$total< $chj_numib){   
  51.     $total++;                                           //总页面数加1  
  52. }  
  53. $total2=$total-1;  
  54. $page2=$page+1;  
  55. $pp=$page*$pagesize+1+$kwnum;                           //计算开始条数  
  56. $pp2=$pp+$pagesize;                                     //计算结尾条数   
  57. $nextpage=$page+2;                                      //下一个页面  
  58. $prevpage=$page;                                        //上一个页面  
  59. $chj_adlen=$chj_numib-1;  
  60. for($i=$pp;$i< $pp2;$i++){  
  61. if($i < $chj_numib){  
  62.     $tmp=explode("|allen|",$msg[$i]);  
  63.     if(!empty($kw)){  
  64.         //有搜索值时  
  65.         $arr[$i]['title']=$tmp[0];  
  66.         $arr[$i]['type']=$tmp[1];  
  67.         $arr[$i]['size']=$tmp[4];  
  68.         $arr[$i]['desc']=$tmp[3];  
  69.         }else{  
  70.         //没有搜索时即显示全部  
  71.         $arr[$i-1]['title']=$tmp[0];  
  72.         $arr[$i-1]['type']=$tmp[1];  
  73.         $arr[$i-1]['size']=$tmp[4];  
  74.         $arr[$i-1]['desc']=$tmp[3];  
  75.     }  
  76.     }  
  77. }  
  78.     $smarty->assign("kw", $kw);  
  79.     $smarty->assign("type", $type);                 //类型标签  
  80.     $smarty->assign("prevpage", $prevpage);         //前一页标签  
  81.     $smarty->assign("nextpage", $nextpage);         //下一页标签  
  82.     $smarty->assign("total2", $total2);                 //页面标签  
  83.     //总条数标签  
  84.     $smarty->assign("page2", "<font color=red>".$page2."</font>/".  
  85.     $total."");  
  86.     $smarty->assign("total", $chj_adlen);               //总条数标签  
  87.     $smarty->assign("content", $arr);                   //生成广告内容标签  
  88.     $smarty->display("./index.html");                   //加载首页模板  

代码的执行流程步骤如下。

(1)加载配置文件(模板引擎配置文件、公共函数库、预定义配置参数)。

(2)判断操作的类型(是否为关键字搜索),使用$kw变量做流程控制。

(3)获取广告内容文件,使用explode()对预先定义的分割标签切割字符串,该条代码如下:

广州网站设计
  1. $msgd=explode("|www_allen|",file_get_contents($dbtable)); 

 

(4)在通过循环遍历,将数组中的字符串取出处理后的再次切割为"内容",处理过程代码如下:
广州网站建设
  1. for($i=$pp;$i< $pp2;$i++){  
  2. if($i < $chj_numib){  
  3.     $tmp=explode("|allen|",$msg[$i]);   //切割字符  
  4.     if(!empty($kw)){                    //判断是否为空  
  5.         $arr[$i]['title']=$tmp[0];  
  6.         $arr[$i]['type']=$tmp[1];  
  7.         $arr[$i]['size']=$tmp[4];  
  8.         $arr[$i]['desc']=$tmp[3];  
  9.         }else{  
  10.         //当为空时为前一个节点数组赋值  
  11.         $arr[$i-1]['title']=$tmp[0];  
  12.         $arr[$i-1]['type']=$tmp[1];  
  13.         $arr[$i-1]['size']=$tmp[4];  
  14.         $arr[$i-1]['desc']=$tmp[3];  
  15.     }  
  16.     }  
  17. }  

 

(5)得到结果数组之后生成Smarty模板标签,代码如下:
广州网站建设
  1. $smarty->assign("kw", $kw);  
  2. $smarty->assign("type", $type);  
  3. $smarty->assign("prevpage", $prevpage);  
  4. $smarty->assign("nextpage", $nextpage);  
  5. $smarty->assign("total2", $total2);         //页面标签  
  6. //总条数标签  
  7. $smarty->assign("page2", "<font color=red>".$page2."</font>/".$total."");  
  8. $smarty->assign("total", $chj_adlen);       //总条数标签  
  9. $smarty->assign("content", $arr);           //生成广告内容标签  
  10. $smarty->display("./index.html");           //加载首页模板  
标签:
飞机