日期:2014-05-17 浏览次数:20439 次
<?php function smarty_function_list($params, &$smarty) { extract($params); $cate = !empty($cate) ? trim($cate) : '';//表名 $items = !empty($items) ? trim($items) : '*';//字段 $length=!empty($length) ? trim ($length) :'10';//长度 $where = !empty($where) ? trim($where) : '';//条件 $order = !empty($order) ? trim($order) : '';//排序 $page = !empty($page) ? intval($page) : 0;//分页 $pagesize = !empty($pagesize) ? intval($pagesize) : 20; $varname = !empty($varname) ? trim($varname) : ''; global $db; global $table; $sql="select $items from ".$table[$cate]; if(!empty($where)) { $sql.=" where $where "; } if(!empty($order)) { $sql.=" order by $order"; } $page=max($page,1); if($pagesize<1) { $pagesize=10; } $rs=$db->PageExecute($sql,$pagesize,$page); $rs=$rs->getRows(); $smarty->assign($length,$length); $smarty->assign($varname, $rs); unset($rs); } ?>
{--list cate="articles" items="Title" length=4 varname="rs"--} {--foreach from=$rs item=r--} {--$r.Title--}<br/> {--/foreach--}