php,php) reads data from the database and displays it in HTML

Source: Internet
Author: User

The first is my database:

Then show me the PHP file:

1 b.php File:2<?PHP3     4     5$link = Mysqli_connect ('localhost','Root','Root');6     //mysqli_character_set_name ();7Mysqli_query ($link,"Set names UTF8");8mysqli_select_db ($link,'THKPHP5');9$sql ='SELECT * from Zixun';Ten$result =mysqli_query ($link, $sql); One$records =Array (); A      while($record =Mysqli_fetch_array ($result)) { -         //the mysql_fetch_array () function acts like the function of a foreach array: traversal (Result set) -         //each time it goes to the result set of "row of data" and "loads" into the array $record the         //The index of the array is the field name of the Select, and the value is the data value of the corresponding row -$records []=$record; -     } - //Var_dump ($records); +Require'login.html'; - //Why can that smooth show, that require ' login.html ', is to copy the login.html page into this b.php file
 ?>

Then the HTML file:

1<!--template files, displaying data with HTML code--2<! DOCTYPE html>3"en">45<meta charset="UTF-8">6<title> Competition List </title>78<body>9 Ten<table> One<tr> A<th>zx_id</th><th>zx_name</th><th>zx_fenlei</th><th>zx_zuozhe</th ><th> Update time </th><th> views </th><th> release Status </th> -</tr> -<?phpforeach($records as$row):?> the<tr> -<td><?php Echo $row ['zx_id'];? ></td> -<td><?php Echo $row ['Zx_name'];? ></td> -<td><?php Echo $row ['Zx_fenlei'];? ></td> +<td><?php Echo $row ['Zx_zuozhe'];? ></td> -<td><?php Echo $row ['Gengxin_time'];? ></td> +<td><?php Echo $row ['Liulan_cishu'];? ></td> A<td><?php Echo $row ['Fabu_zhuangtai'];? ></td> at</tr> -<?php Endforeach;? > -</table> -</body> -

The final results show:

php,php) reads data from the database and displays it in HTML

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.