zoukankan      html  css  js  c++  java
  • dedecms(4)

    1.sql的时间戳

    取出今天更新的电影
    select * from dede_archives where from_unixtime(senddate,'%Y-%m-%d')=curdate();
    
    date_sub(减)和 date_add(加) 函数
    基本用法date_sub(curdate(),interval 数字 时间单位)
    year month minute second day hour
    

    2.电影的星星评分

    		$("#rank_pic img").click(function(){
    		var pfz=($(this).prevAll().length+1)*0.5;
    		var url="{dede:field name='phpurl'/}/pf.php?type=pf&aid={dede:field name='id'/}&pfz="+pfz;
    		$.ajax({
    		  type:"GET",
    		  url:url,
    		  success:function(msg){
    		  $('#rank').html(msg);
    		 // $("#rank").attr('innerHTML'.msg);
    		  }
    		
    		});
    

      

    <?php
    require_once(dirname(__FILE__)."/../include/common.inc.php");
    $type=empty($_GET['type'])?'':$_GET['type'];
    
    if($type==='pf'){
    
      $aid=empty($_GET['aid'])?0:intval($_GET['aid']);
      $pfz=empty($_GET['pfz'])?0:floatval($_GET['pfz']);
      if($aid===0 || $pfz===0){
      echo'参数有误';
      }
      $sql="update dede_addonmovie set pfz=$pfz where aid=$aid ";
    
      if($dsql->ExecuteNoneQuery($sql)){
             $sql="select pfz from dede_addonmovie where aid=$aid";
             $row=$dsql->GetOne($sql);
             if(is_array($row)){
             echo $row['pfz'];
             }
      }else{
            echo'评分失败';
      }
    }
    
    exit;
    

    解决刷新不会再向数据库直接取值的代码

    <font id="rank"><script src="{dede:field name='phpurl'/}/pf.php?type=getpfz&aid={dede:field name='id'/}"></script></font> 分
    

      

    else if($type==='getpfz'){
    		//处理
    		$aid=empty($_GET['aid'])?0:intval($_GET['aid']);
    		$sql="SELECT pfz FROM `#@__addonmovie` WHERE aid=$aid";
    		$dsql->SetQuery($sql);
    		$row=$dsql->GetOne();
    		if(is_array($row)){
    			//这里如果你返回给<script> 脚本,则以document.write返回
    			echo "document.write('".$row['pfz']."');
    ";
    	}
    

     

    3.

    在使用{dede:arclist} 标签时,我们可以指定某个字段排序.
    
    首先在模板[首页模板,列表页模板..]
    

      

    在后台标签库中增加一个逻辑处理:
    	arclist.lib.php 文件
    

      

    4.列表页取分数,取图片

    			{dede:arclist where="language='粤语' " row='10' channelid='17' addfields='language,pfz'}
    				<li class="d[field:global.autoindex/]"><a href="[field:arcurl/]" target="_blank"><img  src="[field:litpic/]" alt="[field:title/]" /></a><p>[field:language/]</p><b><a href="[field:arcurl/]" target="_blank">[field:title/]</a>

    <script src="[field:global.cfg_plus_dir/]/pf.php?type=getstars&aid=[field:id/]"></script> //返回img的html

    <em><script src="[field:global.cfg_plus_dir/]/pf.php?type=getpfz&aid=[field:id/]"></script>分</em></b></li> //返回一个数字 {/dede:arclist}
    else if($type==='getstars'){
       $aid=empty($_GET['aid'])?0:intval($_GET['aid']);
       if($aid===0){
    	     echo'参数有误';
       }
       $sql="select pfz from `#@__addonmovie` where aid=$aid";
       $row=$dsql->GetOne($sql);
       if(is_array($row)){
    	  $pfz=$row['pfz'];
    	  $yellowStars=ceil($pfz/2);
    	  global $cfg_templets_skin;
    	  $htmlstr='';
    	  for($i=0;$i<$yellowStars;$i++){
    		  $htmlstr.="<img src=".$cfg_templets_skin."/images/star.jpg />";
    	  }
    	  for($i=0;$i<5-$yellowStars;$i++){
    		  $htmlstr.="<img src=".$cfg_templets_skin."/images/star_grid.jpg />";
    	  }
    	  echo "document.write('".$htmlstr."');
    ";
       }
    }
    

      

    5.

    分析: 首先我们要自定义一个检索表单.
    后台->内容模型管理->自定义搜索.
    生成表单, 
    2.把表单拷贝index.htm 首页模板
    3.把默认的模板文件 advancedsearch.htm 拷贝 templates/default/ 下.
    4.我把 plus/advancedsearch.php 的 $dlist->pageSize = 2;
    5.提交后可以马上看到分页和检索效果.
    
    把检索的控制器,和检索模板文件换成自己的.
    
    这里有几个重要的知识点:
    这里使用dede:datalist标签来获取查出的结果
    从mysearc.php 的查询语句带回.
    知识点: 
    1. 在{dede:datalist}标签中,可以使用{dede:field.字段名/} 字段名就是$sql语句返回,如果你没有查询这个字段,则无法使用
    2. 在{dede:datalist} 标签中可以使用<?php echo $变量 ?> 变量只有是mysearch.php 有的即可.
    
    最后的代码:
    
    在 /plus/myseach.php 
    

      

    在mysearch.htm 模板文件,是美工提供的 通用列表页.html 改名的.
    
    最后的关键代码是:
    

      

      

      

      

  • 相关阅读:
    POJ 3261 Milk Patterns (求可重叠的k次最长重复子串)
    UVaLive 5031 Graph and Queries (Treap)
    Uva 11996 Jewel Magic (Splay)
    HYSBZ
    POJ 3580 SuperMemo (Splay 区间更新、翻转、循环右移,插入,删除,查询)
    HDU 1890 Robotic Sort (Splay 区间翻转)
    【转】ACM中java的使用
    HDU 4267 A Simple Problem with Integers (树状数组)
    POJ 1195 Mobile phones (二维树状数组)
    HDU 4417 Super Mario (树状数组/线段树)
  • 原文地址:https://www.cnblogs.com/fengzhiqiangcaisangzi/p/3454980.html
Copyright © 2011-2022 走看看