Database query data into a table

Source: Internet
Author: User
Tags import database

querying HTML and PHP for a page

<!doctype html>
<meta charset= "UTF-8" >
<meta name= "Viewport"
Content= "Width=device-width, User-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" >
<meta http-equiv= "x-ua-compatible" content= "Ie=edge" >
<title>Document</title>

<style type= "Text/css" >
table.imagetable {
Font-family:verdana,arial,sans-serif;
font-size:11px;
Color: #333333;
border-width:1px;
Border-color: #999999;
Border-collapse:collapse;
}
table.imagetable th {
Background: #b5cfd2 url (' cell-blue.jpg ');
border-width:1px;
padding:8px;
Border-style:solid;
Border-color: #999999;
}
Table.imagetable TD {
Background: #dcddc0 url (' cell-grey.jpg ');
border-width:1px;
padding:8px;
Border-style:solid;
Border-color: #999999;
}
</style>
<body>
<table class= "ImageTable" >
<tr>
<th>id</th>
<th> name </th>
<th> Password </th>
<th> Sex </th>
<th> Department </th>
<th> class </th>
<th> Telephone </th>
</tr>
<?php


Header (' Content-type:text/html;charset=utf-8 ');


Include_once ("conn/conn.php"); Import Database Control page introduced



$sql = "Select*from user"; Querying the user in the database;

$r =mysqli_query ($link, $sql);

$row =mysqli_fetch_array ($R); Types of arrays queried

while ($row =mysqli_fetch_array ($r)) {
/*print_r ($row);
echo "<br>"; * *
/* echo $row ["name"]. " = ". $row [" Mima "]; Query names and passwords can also be queried by keys
echo "<br>"; * *

?>

<tr>
<td><?php echo $row ["id"]?></td>
<td><?php echo $row ["Name"]?></td>
<td><?php echo $row ["Mima"]?></td>
<td><?php echo $row ["Xingbie"]?></td> <!--data from a database loaded with tables--
<td><?php echo $row ["Xibu"]?></td>
<td><?php echo $row ["Banji"]?></td>
<td><?php echo $row ["Tex"]?></td>


</tr>


<?php
}
?>


</table>
</body>




PHP code in the database


<?php
$host = "localhost";//Specify Host name and IP address
$db _user= "root"; Database user
$db _pass= ""; Database Password
$db _name= "Sqlclass1"; Database Database to use
$timezone = "Asia/shanghai";//Shanghai time

$link =mysqli_connect ($host, $db _user, $db _pass, $db _name);//mysqli_connect open a new connection to the MySQL server
Mysqli_query ($link, "Set names UTF8"),//link is the specified MySQL connection to be used after the encoding format is set
Header ("content-type:text/html; Charset=utf-8 ");
Date_default_timezone_set ($timezone); GMT
?>





Database query data into a table

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.