PHP ~ 原生语法 ~ 根据从数据库查询数据之后快速输出 某个属性的值到 到页面
一,根据 id 来查询单个的数据
<?php
require_once '../../conn.php';
$sql = "select * from blogarticle where ID = {$ID}";
$results = mysql_query($sql);
$blog = mysql_fetch_assoc($results); //将数值存储到 $blog中
mysql_free_result($results);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>name : <?php echo $blog['name']; ?> </h1>
</body>
二,输出表的所有数据
<?php
require_once '../conn.php';
@$sql = "select * from blogarticle";
@$results = mysql_query($sql);
while (@$row = mysql_fetch_assoc($results)) {
echo <<<s
<tr>
<td>{$row['title']}</td>
<td>{$row['content']}</td>
<td>{$row['class']}</td>
<td>{$row['author']}</td>
<td>{$row['date']}</td>
<td>
<a href="../logic/article/delete.php?ID={$row['ID']}">删除 </a>|
<a href="../logic/article/update.php?ID={$row['ID']}">修改</a>
</td>
</tr>
s;
}
mysql_close();
?>