PHP+MYSQL+Javascript数据库查询结果的动态显示
一.查询界面
<html>
<head>
<title>同学查询</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel=stylesheet type="text/css" href="../applet/mainstyle.css">
</head>
<body bgcolor="#FFFFFF">
<form method="post" action="query.php">
<p> </p>
<table width="41%" border="1" cellspacing="0" cellpadding="0" align="center" bordercolor="#808080" bordercolordark="#FFFFFF" bgcolor="#ffffcc">
<tr>
<td colspan="2" class="tablehead" bgcolor="#0066cc" align="center">同学查询</td>
</tr>
<tr>
<td width="23%"> 姓名: </td>
<td width="77%">
<input type="text" name="name" size="20" class="edit">
</td>
</tr>
<tr>
<td width="23%">性别:</td>
<td width="77%">
<input type="radio" name="sex" value="1" checked>
全部
<input type="radio" name="sex" value="2">
男
<input type="radio" name="sex" value="3">
女 </td>
</tr>
<tr>
<td> 属性:</td>
<td>
<input type="text" name="attribute" size="20" class="edit">
</td>
</tr>
<tr>
<td>输出:</td>
<td>
<input type="radio" name="output" value="1" checked>
标签
<input type="radio" name="output" value="2">
表格 </td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="Submit" value="查询" class="button">
</td>
</tr>
</table>
</form>
</body>
</html>
二.执行查询和动态显示的界面
<!--同学录查询系统:PHP+MYSQL+javascript-->
<html><head>
<link rel=stylesheet type="text/css" href="../applet/mainstyle.css">
<script language="javascript">
//标签显示时隐藏和打开选择的table
function showtable(id,totalnum)
{
for(i=0;i<totalnum;i++)
eval("table"+i.toString()+".style.display=none");
eval("table"+id.toString()+".style.display=");
}
</script>
</head><BODY>
<?
#连接和打开数据库
$dbh = mysql_connect("localhost");
$err = mysql_error();
if($err){die("连接错误");}
mysql_select_db(mydb);
$err = mysql_error();
if($err){die("打开数据库错误");}
#建立查询语句
if((trim($name)!="")&&(trim($attribute)!=""))
$query="select * from addressbook where name="".$name."" and attribute="".$attribute.""";
else if((trim($name)=="")&&(trim($attribute)==""))
$query="select * from addressbook where 1";
else if(trim($name)=="")
$query="select * from addressbook where attribute="".$attribute.""";
else if(trim($attribute)=="")
$query="select * from addressbook where name="".$name.""";
if($sex=="2")
$query=$query." and sex="男"";
else if($sex=="3")
$query=$query." and sex="女"";
#查询数据库
$ret = mysql_query($query, $dbh);
$num=mysql_num_rows($ret);
if($num<=0)
{
echo "<Script language="javascript">window.alert("没有符合条件的记录!");history.back();</script>";
exit;
}
if($output=="2")#表格形式输出
{
echo "<table width="100%" border="1" cellspacing="0" cellpadding="0" bordercolor="#808080" align="center" bordercolordark="#ffffff">
<tr>
<td colspan="13" align="center" class="tablehead" bgcolor="#0066cc">查询结果</td>
</tr>
<tr bgcolor=#ffffcc>
<td nowrap width="2%">姓名</td>
<td nowrap width="1%">性别</td>
<td nowrap width="4%">生日</td>
相关新闻>>
- 发表评论
-
- 最新评论 更多>>