国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > 建站經(jīng)驗(yàn) > 正文

smarty簡單應(yīng)用實(shí)例

2024-04-25 20:43:03
字體:
供稿:網(wǎng)友

本文講述了smarty簡單應(yīng)用實(shí)例。分享給大家供大家參考,具體如下:

<?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服務(wù)器連接

mysql_select_db("lava_guess"); //鏈接數(shù)據(jù)庫

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); //執(zhí)行sql語句,返回結(jié)果

//把記錄集轉(zhuǎn)換為數(shù)組

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

<html>

<head>

<metahttp-equiv="Content-Type" content="text/html;charset=utf-8">

<title>Smarty</title></head>

<body>

<hr>

{$hello}

<hr>

{section name=loop loop=$msglist}

id: {$msglist[loop].id}--{$msglist[loop].title}----{$msglist[loop].receiver}<br>

{/section}

<hr>

{section name=loop loop=$newsArray}

新聞編號:{$newsArray[loop].newsID}<br>

新聞標(biāo)題:{$newsArray[loop].newsTitle}<br><hr>

{sectionelse}

對不起,沒有任何新聞輸入!

{/section}

希望本文所述對大家基于smarty模板的php程序設(shè)計(jì)有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 晋中市| 大石桥市| 东乡县| 石狮市| 泾川县| 香格里拉县| 彰化县| 清镇市| 方正县| 宜宾县| 上蔡县| 瑞丽市| 武邑县| 玉屏| 新密市| 五指山市| 东莞市| 翁源县| 师宗县| 鄂伦春自治旗| 乃东县| 孟州市| 林西县| 水富县| 延庆县| 施秉县| 肥东县| 工布江达县| 平邑县| 木兰县| 绥棱县| 文水县| 盐津县| 岳阳县| 远安县| 昭苏县| 松滋市| 尼玛县| 侯马市| 德惠市| 铁力市|