How to display the tables in the MySQL database using the smarty template? How to Handle

Source: Internet
Author: User
Tags smarty template
How to display the tables in the MySQL database using the smarty template?
I'm new to PHP. For Smarty is less, before using PHP to write a page, simple to use the database content display in the form of a table display to the Web page.
But the problem comes, the table is more and more, refresh the page each time will occupy the majority of the CPU, found that this does not work, so the search for a cache problem. And then we found Smarty.
These days have also seen a few examples, and some video, I have done a lot of tests, or do not know how to start the database table with Smarty template display.
The tables are simple.
database table name. my_db
ID Name Gender age Height Weight ID number home Address contact phone
1 Three men 173cm 66 100******** 134*******, Dongcheng District, Beijing
2 Li four men 178cm 65 100******** 134*******, Xicheng District, Beijing
3 Harry male 179cm 63 100******** 134*******, Dongcheng District, Beijing
4 Zhao Liu Male 181cm 67 100******** 186*******, Dongcheng District, Beijing
5 Little Red Girl 143cm 40 100******** no telephone in Fangshan district, Beijing
6 Xiao Ming male 163cm 55 100******** No telephone in Fangshan district, Beijing
7 Xiao Li male 155cm 45 100******** Beijing Xicheng District No telephone
I want to show the size of the page by age, but with smarty I really don't know how to do it, I don't know how to write it. Forum also did not find such an example should be how to write, hope will be friends to me to do a type of help me write. Thank you very much!!
A bit is the source of the enthusiastic person to give:
PHP Code
  
   The table method, which is used to query the database function table () {   //Initialize the library functions, where $conn is a previously instantiated PDO   globle $conn;  Query $sel by condition  = $conn->query ("SELECT * from my_db ORDER by age");  Returns the variable to the function  return $sel->fetchall ();} $smarty->assign (' Table ', table ());

But PDO is useless, can you use such a.
PHP Code
  
   Include ("smarty_inc.php"), $con = mysql_connect ("127.0.0.1", "User", "123456"), if (! $con)  {die (' Could not connect: ' . Mysql_error ());  } $db =new PDO (' mysql:127.0.0.1;mysql ', ' user ', ' 123456 ', ' true '), mysql_query ("Set names GBK"); mysql_select_db ("Test" , $con); $result =mysql_query ("SELECT * from my_db");

How it should be changed and presented in such a way!


------Solution--------------------
PHP file
PHP code
!--? phpinclude ("smarty_inc.php"); $con = Mysql_ Connect ("127.0.0.1", "User", "123456"), if (! $con) die (' Could not connect: '. Mysql_error ()); mysql_query ("Set names GBK") ; mysql_select_db ("Test", $con); $result =mysql_query ("SELECT * from my_db order by"); while ($row =mysql_fetch_assoc ($ Result) {$table []= $row;} $smarty--->assign (' table ', $table); 
------Solution--------------------
The foreground assigns a value to a variable using the assign of Smarty. The Smarty section is then used to cycle through the display.
  • 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.