-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-
<title>Untitled document</title>
-
<style type="text/css">
-
table{
-
border: 1px solid black;
-
border-color:#F06;
-
padding:10px;
-
border-collapse:collapse;
-
}
-
table tr th{
-
border: 1px solid black;
-
border-color:#F06;
-
padding:10px;
-
border-collapse:collapse;
-
}
-
table tr td{
-
border: 1px solid black;
-
border-color:#F06;
-
padding:10px;
-
border-collapse:collapse;
-
}
-
</style>
-
</head>
-
<body>
-
<center>
-
<table>
-
<caption>List of results</caption>
-
<tr><th>Number</th><th>Name</th><th>Email</th><th>Results</th><th>Time</th></tr>
-
<?php
-
//header("Content-Type:text/html;charset=utf-8");//Set the page character encoding
-
// constant parameters
-
define("DB_HOST", 'localhost');
-
define("DB_USER", 'root');
-
define("DB_PWD",'123');
-
define("DB_NAME", 'school');
-
// The first step is to connect to the database
-
$conn = mysql_connect('localhost','root','123') or die('Database connection failed, error message:'.mysql_error());
-
-
// The second step is to select the specified database and set the character set
-
mysql_select_db(DB_NAME,$conn) or die('Database error, error message:'.mysql_error());
-
mysql_query('SET NAMES UTF8') or die('Character set setting error:'.mysql_error());
-
-
//Add data
-
// $query = "INSERT INTO grade(name,email,point,regdate)
-
// VALUES('nurse','[email protected]',67,NOW())";
-
// mysql_query($query) or die('New error:'.mysql_error());
-
// change the data
-
// $query = 'UPDATE grade SET point = 87 WHERE id = 7';
-
// @mysql_query($query) or die('Modification error:'.mysql_error());
-
//delete data
-
// $query = 'DELETE FROM grade WHERE id = 7';
-
// @mysql_query($query) or die('Delete error:'.mysql_error());
-
// Display Data
-
$query = 'SELECT * FROM grade';
-
$result = mysql_query($query) or die('SQL statement error:'.mysql_error());
-
-
// Convert the result set into an array and assign it to $row, if there is data, it is true
-
while(!!$row = mysql_fetch_array($result)){
-
echo"<tr><td>".$row["id"]."</td><td>".$row["name"]."</td><td>".$row["email"]."</td><td>".$row["point"]."</td><td>".$row["regdate"]."</td><tr>";
-
}
-
mysql_close($conn);
-
?>
-
</table>
-
<a href="#">返回</a>
-
</center>
-
</body>
-
</html>
Retrieve data from the database and display it to the page PHP+Mysql+Html (simple example)
Guess you like
Origin blog.csdn.net/keke795/article/details/113065900
Recommended
Ranking