html+php+mysql使用网页对数据库的搜索和结果显示。
html 里建立表单,action属性设为php文件,input 的name属性就是提交到php中的变量名。
<pre name="code" class="html"><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<title>homework1</title>
</head>
<body>
<div>
<h1>search student information by ID</h1>
<form method="post"
enctype="applicantion/x-www-form-unlencoded"
action="searchStudentByID.php"
target="_blank">
<p><label>Student ID:<input type="text" name="ID"></label></p>
<p><button>Search</button></p>
</form>
<form method="post"
enctype="applicantion/x-www-form-unlencoded"
action="searchStudentByClass.php"
target="_blank">
<p><label>Class:<input type="text" name="class"></label></p>
<p><button>Search</button></p>
</form>
<br>
</div>
</body>
</html>
建立数据库
从txt导入记录,把excel 里写好的记录复制到txt,也就是tab分隔。
create ....
load data local infile"path/*.txt" into table table_name(no,name);
php接收数据和查询数据库,返回结果。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
</head>
<body>
<?php
function databaseConnect($db,$dbserver="210.77.20.246")
{
$dbuser="201428010415022";
$dbpass="5022";
if($link=mysql_pconnect($dbserver,$dbuser,$dbpass))
if(mysql_select_db($db,$link)){ return $link;}
else return 0;
else return 0;
}
$db='201428010415022';
$dbLink=databaseConnect($db);
?>
<table border="1">
<tr>
<td>学号</td>
<td>姓名</td>
<td>单位</td>
<td>班级</td>
<?php
mysql_query("SET NAMES utf8");
$stu_id=$_POST['ID'];
if($stu_id=='')
{
$myquery1="select * from `$db`.`student_info`";
$result1=mysql_query($myquery1);
while($row=mysql_fetch_array($result1)){
echo "<tr>
<td>".$row['ID']."</td>
<td>".$row['name']."</td>
<td>".$row['unit']."</td>
<td>".$row['class']."</td>
</tr>";
}
}
else{
$myquery1="select * from `$db`.`student_info` where `ID`='$stu_id'";
$result1=mysql_query($myquery1);
while($row=mysql_fetch_array($result1)){
echo "<tr>
<td>".$row[0]."</td>
<td>".$row[1]."</td>
<td>".$row[2]."</td>
<td>".$row[3]."</td>
</tr>";
}
}
?>
</table>
</body>
</html>