How can I use the smarty Template to display tables in the mysql database? How to deal with it-php Tutorial

Source: Internet
Author: User
How can I use the smarty Template to display tables in the mysql database? I am new to php. there are even fewer smarty users. I wrote a page in php and simply used the database content to display it on the webpage as a table. but the problem is that there are more and more tables. every time you refresh the page, it will take up most of the CPU resources. I find that this is not the case, so I found the cache problems. then I found out that smarty has not seen some examples in the past few days. I have also done some videos. how can I use the smarty Template to display the tables in the mysql database?
I am a newbie who just got in touch with php. There are even fewer smarty users. I used php to write a page and simply used the database content to display it on the webpage as a table.
But the problem is that there are more and more tables. every time you refresh the page, it will take up most of the CPU resources. if this is not the case, you will find the cache problems. then you will find smarty.
I have not seen some examples in the past few days. I have also done many tests with some videos, but I still don't know how to display the database tables with the smarty template ..
The table is simple.
Database table name. my_db
Id name gender age height weight id card number home address contact number
1 Zhang Weinan 32 173 66 100 ********* 134, Dongcheng district, Beijing *******
2 Li Si male 30 178 65 100 ******** 134, Xicheng district, Beijing *******
3 Wang Wu male 30 179 63 100 ********* Beijing Dongcheng District 134 *******
4 Zhao liumale 29 181 cm 67 100 ******** 186, Dongcheng district, Beijing *******
5 Red female 12 143 cm 40 100 ********* no phone number in Fangshan district, Beijing
6 James Male 14 163 55 100 ********* no phone number in Fangshan district, Beijing
7 Xiao Li Male 12 155 45 100 ********* no phone number in Xicheng district, Beijing
I want to display the information on the webpage by age, but I really don't know how to start with smarty .. I have not found such an example on the forum. I hope my friends can help me write it for me. thank you !!
The following is the source code provided by enthusiastic people:
PHP code
  // Table method, used to query the database function table () {// initialize the database connection function. Here $ conn is the previously instantiated pdo globle $ conn; // query by condition $ sel = $ conn-> query ("select * from my_db order by age "); // return the variable to the function return $ sel-> fetchAll () ;}$ smarty-> assign ('table', table ());

But pdo has never been used. can it be used ..
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 should I change it to and then present it in this way!


------ Solution --------------------
Php file
PHP code
  Assign ('table', $ table );
------ Solution --------------------
The foreground uses the assign of smarty to assign values to variables. Then, use the section of smarty to display it cyclically.

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.