首页 / PHP / smarty简单应用实例_php实例
smarty简单应用实例_php实例
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了smarty简单应用实例_php实例,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1780字,纯文字阅读大概需要3分钟。
内容图文
本文讲述了smarty简单应用实例。分享给大家供大家参考,具体如下:<?php require 'smarty/libs/Smarty.class.php'; $smarty = new Smarty; $smarty->template_dir="smarty/templates/templates"; $smarty->compile_dir="smarty/templates/templates_c"; $smarty->config_dir="smarty/templates/config"; $smarty->cache_dir="smarty/templates/cache"; $hello = "Hello World!"; $smarty->compile_check = true; //$smarty->debugging = true; $smarty->debugging = false; $smarty->caching=true; $conn=mysql_connect("localhost", "root","root"); //打开MySQL服务器连接 mysql_select_db("lava_guess"); //链接数据库 mysql_query("set names utf8"); //解决中文乱码问题 $sql_list="Select * from t_sys_msg Order by id desc limit 0,10"; $result_list=mysql_query($sql_list); //执行sql语句,返回结果 //把记录集转换为数组 while($rs_list=mysql_fetch_array($result_list)) { $msg_array[]=$rs_list; } $array[] = array("newsID"=>1, "newsTitle"=>"第1条新闻"); $array[] = array("newsID"=>2, "newsTitle"=>"第2条新闻"); $array[] = array("newsID"=>3, "newsTitle"=>"第3条新闻"); $array[] = array("newsID"=>4, "newsTitle"=>"第4条新闻"); $array[] = array("newsID"=>5, "newsTitle"=>"第5条新闻"); $array[] = array("newsID"=>6, "newsTitle"=>"第6条新闻"); $smarty->assign("newsArray", $array); $smarty->assign("hello",$hello); //赋值 $smarty->assign("msglist",$msg_array); $smarty->display('index.tpl'); ?>
模板文件:index.tpl
<metahttp-equiv="Content-Type" content="text/html;charset=utf-8">Smarty
{$hello}
{section name=loop loop=$msglist} id: {$msglist[loop].id}--{$msglist[loop].title}----{$msglist[loop].receiver}
{/section}
{section name=loop loop=$newsArray} 新闻编号:{$newsArray[loop].newsID}
新闻标题:{$newsArray[loop].newsTitle}
{sectionelse} 对不起,没有任何新闻输入! {/section}
希望本文所述对大家基于smarty模板的php程序设计有所帮助。
内容总结
以上是互联网集市为您收集整理的smarty简单应用实例_php实例全部内容,希望文章能够帮你解决smarty简单应用实例_php实例所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。