zoukankan      html  css  js  c++  java
  • 前台任意页面调用自定义字段选项 box 单选 多选方法及查询

    在模板页增加函数,函数写法比较特殊,但是v9模板引擎nb,能够识别
     

     <?
                  function xbox($field,$na){
                   $a=pc_base::load_config('database','default');
                    $model_field = $a['tablepre']."model_field";
                  ?>
                    {pc:get sql="select * from $model_field where field = '$field'" num="1"}
                    <?
                    $a1 = string2array($data[0][setting]);
                $options = explode(" ",$a1[options]);
                foreach($options as $_k){
                $v = explode("|",$_k);
                $k = trim($v[1]); 
                $options[$k] = $v[0];
                }
                return $options[$na];
                ?>
                    {/pc}
                    <?
                     }
                    ?>

    <?
    function duoxuanbox($field,$naa){
        $arr_mx = explode(",",$naa);
        $cx = "";
            foreach($arr_mx as $_k){
            $cx .= xbox($field,$_k).",";
            }
        return trim($cx,',');
    }
    ?>        

    有了这两个函数后,可以通过下面方法调用 如本来{$r[abc]}只能够调用出abc的1,2,3...,但是:{xbox("abc",$r[abc])}就可以调用出1对应的中国 2对应的北京 3对应的海淀区

    如果你要查询海淀区的信息,可以使用下面代码

     

    {php $where="true and catid=12 and abc=3"}
    {pc:content action="lists" catid="12" num="1" where="$where" order="id desc"}
       {loop $data $r}
    <li>【<a href="{$categorys[$r[catid]][url]}">{$categorys[$r[catid]][catname]}</a>】<a href="{$r[url]} " target="_blank" title="{$r[title]}" class=""> {$r[title]}</a></li>
      {/loop}
    {/pc}

    注意使用$where以后,catid值需要定义在$where里面

     
     
     

    <?
    function getbox($modelid,$field,$na){
    $field_db = pc_base::load_model('sitemodel_field_model');
    //print_r($field_db);
    $data =$field_db->get_one(array('modelid'=>$modelid,'field'=>$field));
                $a1 = string2array($data[setting]);
                $options = explode(" ",$a1[options]);
                foreach($options as $_k){
                $v = explode("|",$_k);
                $k = trim($v[1]); 
                $options[$k] = $v[0];
                }
                return $options[$na];
    }
    ?>
    <!--getbox($modelid,"brand",$r[brand])-->

  • 相关阅读:
    日常学习随笔-数组、单链表、双链表三种形式实现队列结构的基本操作(源码注释)
    代码重构之单元测试
    C# yield return 用法与解析
    MVC学习手册之数据注解与验证
    C#数字图像处理算法学习笔记(三)--图像几何变换
    关于变量名与类名同名问题
    C# 计时器
    C#入门--索引器
    C#入门--字段与属性
    var与dynamic
  • 原文地址:https://www.cnblogs.com/semcoding/p/3358749.html
Copyright © 2011-2022 走看看