Smarty processes mysql Query arrays

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.