查询图书价格php+ mysql

<html>
<head><meta charset="utf-8"></head>
<body>
<h1>图书查询系统</h1>
<form action="" method="post">
<input type="radio" value='no' name='xuanze'>图书编号
<input type="radio" value='name' name='xuanze'>书名
<input type='radio' value='author' name='xuanze'>作者<br><br>
请输入已知信息:<input type="text" name="nu"><br><br>
<input type="submit">
</form>
<table border="1">
<?php
@$nu=$_POST['nu'];
$sql=mysql_connect('localhost','root','admin');//连接打开数据库
mysql_select_db('shudian',$sql);


$ziduan=mysql_list_fields('shudian','shu');//取出表中的字段,以表格方式显示。
$num=mysql_num_fields($ziduan);
echo "<tr>";
for($i=0;$i<$num;$i++)

{
  $dd=mysql_field_name($ziduan,$i);
  echo "<td>".$dd."</td>";
}
echo "</tr>";


if(@$_POST['xuanze']=='no')//判断表单的查询方式

{

  $command="select * from shu where sno like '%".$nu."%'";//设置查询命令
  $file=mysql_query($command,$sql) or die(mysql_error);

}
else if(@$_POST['xuanze']=='name')

{
  $command="select * from shu where sname like '%".$nu."%'";
  $file=mysql_query($command,$sql) or die(mysql_error);

}
else{
  $command="select * from shu where author like '%".$nu."%'";
  $file=mysql_query($command,$sql) or die(mysql_error);

  }


while($array=mysql_fetch_array($file,MYSQL_NUM))//以表格形式输出信息

{
 echo "<tr>";
 for($i=0;$i<count($array);$i++)
 {echo "<td>".$array[$i]."</td>";}
 echo "</td>";
}
?>
</table>
</body>
</html>

原文地址:https://www.cnblogs.com/anqi/p/3296158.html