Smarty processes mysql Query array
MySQL Query results are generally an array instead of all result sets. Therefore, we need to save all the results to the array for processing, and then we can easily use it in Smarty.
PHP Mysql code
$ 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 =" {<"; // custom HTML conflicts can be avoided. $ smarty-> right_delimiter ="> }"; // I can customize it to avoid conflicts with HTML. $ smarty-> assign ('doclist', $ record); $ smarty-> display ('index. tpl ');Smarty template code
{
}
} ">{< $ Curr_item.title>}
{
}
In this way, the problem of page display and template can be perfectly solved.