读取数据库内容到页面:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{
background: #009899;
position: relative;
}
table{
border-collapse: collapse;
border: 1px solid #006566;
position: absolute;
top: 100px;
left: 100px;
cursor: pointer;
800px;
}
img {
50px;
height: 50px;
}
</style>
</head>
<body>
<div></div>
<table >
<?php
$con = mysql_connect("localhost","root","root");
if(!$con){
die("db connection is wrong:".mysql_errno());
}
mysql_select_db("db_admin",$con);// db_admin数据库名
mysql_query("set names utf8");//把数据库读出的乱码中文正常显示
//遍历表中的数据在浏览器里输出
$sql1 = "select * from song limit 0,10"; // limit 0,10显示数据库前10行,song为表名
$str = mysql_query($sql1);
while($infor = mysql_fetch_array($str)){
echo "<tr><td>".$infor['id']."</td>
<td>". $infor['song_name']."</td>
<td><img src='". $infor['song_icon_url']."'></td>
<td><audio controls src='song/". $infor['song_url']."'></audio></td></tr>";
}
mysql_close($con);
?>
</table>
</body>
</html>