简明现代魔法 -> PHP服务器脚本 -> PHP查询数据库功能设计
PHP查询数据库功能设计
2009-08-17
完整代码
数据库建表语句在这里:visitors
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="generator" Content="Microsoft Visual Studio 6.0">
<style type="text/css">
<!--
input { font-size:9pt;}
A:link {text-decoration: underline; font-size:9pt;color:000059}
A:visited {text-decoration: underline; font-size:9pt;color:000059}
A:active {text-decoration: none; font-size:9pt}
A:hover {text-decoration:underline;color:red}
body,table {font-size: 9pt}
tr,td{font-size:9pt}
-->
</style>
<title>数据库查询 - 读取MySQL的测试</title>
</head>
<body alink="#FF0000" link="#000099" vlink="#CC6600" topmargin="8" leftmargin="0" bgColor="#FFFFFF">
<br><br><center><font color=green size=3><b>数据库查询结果</b></font></center>
<br>
<table cellspacing=0 bordercolordark=#FFFFFF width="95%" bordercolorlight=#000000 border=1 align="center" cellpadding="2">
<tr bgcolor="#6b8ba8" style="color:FFFFFF">
<td width="5%" align="center" valign="bottom" height="19">姓名</td>
<td width="10%" align="center" valign="bottom">公司名称</td>
<td width="5%" align="center" valign="bottom">职位</td>
<td width="20%" align="center" valign="bottom">公司地址</td>
<td width="5%" align="center" valign="bottom">邮编</td>
<td width="10%" align="center" valign="bottom">电话</td>
<td width="10%" align="center" valign="bottom">传真</td>
<td width="10%" align="center" valign="bottom">电子邮件</td>
<td width="10%" align="center" valign="bottom">公司网站</td>
<td width="10%" align="center" valign="bottom">修改|删除</td>
</tr>
<?php
//连接到本地MySQL数据库
$myconn=mysql_connect("localhost","root","");
//选择info为操作对象数据库
mysql_select_db("info",$myconn);
$strSql="select * from visitors";
//用mysql_query函数从user表里读取数据
$result=mysql_query($strSql,$myconn);
while($row=mysql_fetch_array($result))//通过循环读取数据内容
{
?>
<tr>
<td align="center" height="19"><?echo $row["name"]?></td>
<td align="center"><?echo $row["companyname"]?></td>
<td align="center"><?echo $row["position"]?></td>
<td align="center"><?echo $row["address"]?></td>
<td align="center"><?echo $row["postcode"]?></td>
<td align="center"><?echo $row["tel"]?></td>
<td align="center"><?echo $row["fax"]?></td>
<td align="center"><?echo $row["email"]?></td>
<td align="center"><?echo $row["website"]?></td>
<td align="center">修改 删除</td>
</tr>
<?php
}
//关闭对数据库的连接
mysql_close($myconn);
?>
</table>
</body>
</html>

