Original php file code:
<? Php
Include_once ("./comm/Smarty. class. php"); // contains the smarty class file
Define ("NUM", 5); // defines the number of news entries displayed each time.
$ Smarty = new Smarty (); // Create a smarty instance object $ smarty
$ Smarty-> templates_dir = "./templates"; // set the template directory
$ Smarty-> compile_dir = "./templates_c"; // Set the compilation Directory
$ Smarty-> cache_dir = "./cache"; // you can specify a cache directory.
$ Smarty-> cache_lifetime = 60*60*24; // you can specify the cache time.
$ Smarty-> caching = false; // set this parameter to false during debugging. Use true for release.
$ Smarty-> left_delimiter = "<{"; // you can specify the left boundary.
$ Smarty-> right_delimiter = "}>"; // you can specify the right boundary.
$ Db = mysql_connect ('localhost', 'root', '123 ');
Mysql_select_db ('Liu ', $ db );
$ SQL = "select id, title from lyb ";
Mysql_query ("set names gb2312 ");
$ Result = mysql_query ($ SQL, $ db );
While ($ row = mysql_fetch_array ($ result )){
$ Array [] = array ("id" => $ row ['id'],
"Title" => $ row ['title']);
}
Mysql_close ();
$ Smarty-> assign ('new', $ array );
$ Smarty-> display('3.html ');
?>
3. html
<Table width = "100%" border = "0" cellpadding = "0" cellspacing = "0" bgcolor = "# B9E9FF">
<Tr>
<Td height = "115" width = "10"> </td>
<Td valign = "top" width = "295" bgcolor = "# B9E9FF">
<{Section name = loop = $ new}>
<{$ New [loop]. id}>
<{$ New [loop]. title}> <br>
<{/Section}>
</Td>
</Tr>
</Table>
Now let's explain: Things in 3. php.
Let's take a look at the process writing!
$ Smarty = new Smarty (); // Create a smarty instance object $ smarty
$ Smarty-> templates_dir = "./templates"; // set the template directory. This must exist (the HTML file is here)
$ Smarty-> compile_dir = "./templates_c"; // Set the compiling directory to be real (compiled directory)
$ Smarty-> cache_dir = "./cache"; // you can specify a cache directory.
$ Smarty-> cache_lifetime = 60*60*24; // you can specify the cache time.
$ Smarty-> caching = false; // set this parameter to false during debugging. Use true for release.
$ Smarty-> left_delimiter = "<{"; // you can specify the left boundary.
$ Smarty-> right_delimiter = "}>"; // you can specify the right boundary.
$ Smarty-> assign ('new', $ array); // This is the section LOOP value of new in html.
$ Smarty-> display('3.html '); // which HTML file is this.
In html,. <{section name = loop = $ new}>
<{$ New [loop]. id}>
<{$ New [loop]. title}> <br>
<{/Section}>