• 前台任意页面调用自定义字段选项 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])-->

  • 相关阅读:
    API函数
    平台调用教程
    查看网页源文件方法
    网页端商品链接转换为手机端链接的部分网址规则
    中文分词消除歧义简单思想
    java 链接数据库时的配置代码
    手机参数更新语句根据Id 可以得到某手机的各种参数
    中文分词—基于Lucene的分词器—支持中英文混合词
    修改Imdict做自己的分词器
    制作可输入的下拉框
  • 原文地址:https://www.cnblogs.com/semcoding/p/3358749.html
Copyright © 2020-2023  润新知