s
o
u
l
s
j
i
e

PHP读取mysql中的数据

<!DOCTYPE HTML>
<html>
	<head>
		<title>
			PHP动态读取mysql中的数据
		</title>
		<meta charset="gb2312">	
	</head>
	<body>
		<h1>用户管理:</h1>
		<?php
			//连接数据库
			$pdo=new PDO('mysql:host=localhost;dbname=ajax_stydy','root','root');
			$pdo->exec('set names gb2312');
			$sql="select * from user";
			$smt=$pdo->query($sql);
			$rows=$smt->fetchAll(PDO::FETCH_ASSOC);
			//获取数据
		?>
		<table width="700px" border="1px" cellspacing="0px">
			<tr>
				<th>ID</th>
				<th>用户名</th>
				<th>密码</th>
				<th>操作</th>
			</tr>
		<?PHP
    
		foreach($rows as $row){
			echo"<tr>";
			echo"<td>{$row['Id']}</td>";
			echo"<td>{$row['username']}</td>";
			echo"<td>{$row['pass']}</td>";
			echo"<td><a href='delete.php?id={$row['Id']}'>删除用户</a></td>";
			echo"</tr>";
			}
		
		?>
		</table>
	</body>
	
</html>
        

 

posted @ 2017-10-18 19:27  soulsjie  阅读(705)  评论(0编辑  收藏  举报
你累吗?累就对了,当你觉得累时证明你在走上坡路!-----NotFoundObject - 2016-12-14 08:43