在模板页增加函数,函数写法比较特殊,但是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])-->