您的位置:首页 > 编程语言 > PHP开发

PHP+MYSQL数据库查询显示

2015-10-20 16:56 711 查看
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>会员列表</title>
</head>
<?php
$link = mysql_connect("localhost","root","");//连接MySQL服务器
$db  = mysql_select_db("club");//选择数据库

mysql_query("set names utf8",$link);//设定编码方式
$sql = "Select * from member";
$result = mysql_query($sql,$link);//执行SELECT查询
$num = mysql_num_rows($result);//获取记录条数
?>
<body>
<h1>健身俱乐部 会员名册</h1>
<br />
点击姓名可查看该会员详细资料,现有会员<? echo $num?>人。
<br />
<?php
if($num > 0)
{
?>
<table border="1" cellpadding="1" cellspacing="1">
<tr>
<td>序号</td>
<td>姓名</td>
<td>性别</td>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
echo "<tr><td>" . $row['id'] . "</td><td><a href=member.php?name=" . $row['name'] . ">" . $row['name']. "</a></td><td>" . ($row['sex']==1?"女":"男") . "</td></tr>";
}
?>
</table>
<?php
}
else
{
echo "俱乐部尚未发展会员。";
}
?>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: