index.php<?php
require './libs/Smarty.class.php';
// This is a file which abstracts the DB connecting functionality (Check out PEAR)
$smarty = new Smarty;
$smarty->template_dir = './templates/default/';
$smarty->compile_check = true;
//$smarty->debugging = true;
//$smarty->use_sub_dirs = false;
//$smarty->caching = true;
$db = mysql_connect("localhost","root","");
mysql_select_db("test");
// This SQL statement will get the 5 most recently added new items from the database
$sql = 'SELECT * ';
$sql .= 'FROM `news` ';
$sql .= 'ORDER BY `id` DESC';
$result = mysql_query($sql) or die("Query failed : " . mysql_error());
// For each result that we got from the Database
while ($line = mysql_fetch_assoc($result))
{
$value[] = $line;
// Assign this array to smarty...
}
$smarty->assign('news', $value);
/*@!@!#@$!$!#!@$!@$!$!@#@~!$
yes ,i change it here ,
i learn just a little,knowing that $**[] main autoincrease from 0
then assign an array called $** to 'news' in *.tpl
hahahahah^^ ,now my que~ has been solved!
*/
// Display the news page through the news template
$smarty->display('news.tpl');
?>
news.tpl
{$title}Steve's News Page
Read All About It
{section name=news loop=$news}
{$news[news].title}
{$news[news].author}, {$news[news].date}
{$news[news].article}
{/section}