homework2

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>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值