跳至内容
Python 俱乐部
用户工具
登录
站点工具
搜索
工具
显示页面
修订记录
反向链接
最近更改
媒体管理器
网站地图
登录
>
最近更改
媒体管理器
网站地图
您的足迹:
php:smarty:mysql-loop
本页面只读。您可以查看源文件,但不能更改它。如果您觉得这是系统错误,请联系管理员。
====== Smarty处理mysql查询数组 ====== MySQL的查询结果一般是一个数组,而不是所有结果集。因此我们需要将结果全部存到数组中进行处理,然后就可以很轻松的再Smarty中使用了。 ===== PHP Mysql 代码 ===== <code php> $sql="select article_id,article_title from tbl_article order by article_id desc limit 0,5"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)) { $record[]=array('id'=>$row['article_id'],'title'=>$row['article_title']); } $smarty = new Smarty; $smarty->template_dir ="./template"; $smarty->compile_dir ="./templates_c"; $smarty->left_delimiter = "{<";//我自己自定义的可以避免与HTML冲突 $smarty->right_delimiter = ">}"; //我自己自定义的可以避免与HTML冲突 $smarty->assign('doclist',$record); $smarty->display('index.tpl'); </code> ===== Smarty 模板代码 ===== <code> {<foreach from=$doclist item=curr_item>} <div><a href="show.php?id={<$curr_item.id>}">{<$curr_item.title>}</a></div> {</foreach>} </code> 这样就可以完美解决分页显示和模板的问题了。
php/smarty/mysql-loop.txt
· 最后更改: 2014/05/26 13:40 (外部编辑)
页面工具
显示页面
修订记录
反向链接
回到顶部