都能实现相同功能,,但是在用法有一点点不一样
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
<title>这是我的第一个php程序</title>
</head>
<body>
<form name="myform" method="post" action="">
<table width="605" border="1" cellpadding="1" bordercolor="#FF00CC" bgcolor="#CC6600">
<tr>
<td width="118" height="24" align="right" bgcolor="#0000FF">
请输入图书名称
<input name="txt_book" type="text" id="txt_book" size="25"/>
<input type="submit" name="submit" value="查询"/>
</td>
</tr>
</form>
<<?php
echo "用mysqli";
error_reporting(E_ALL & ~E_NOTICE);
$link=mysqli_connect("localhost","root","root")or die("数据库连接失败".mysqli_error());
mysqli_select_db($link, "phpmysql");
$sql=mysqli_query($link, "select * from tb_book");
if($_POST[submit]=="查询"){
$text_book=$_POST[txt_book];
//如果选择的条件为"like",则进行模糊查询
$sql=mysqli_query($link,"select * from tb_book where bookname like '%".trim($text_book)."%'");
$info=mysqli_fetch_array($sql);
}
if($info==false){
echo "<div align='center' style='color:#FF0000;font-size:12px'>对不起,您检索的图书信息不存在!</div> ";
}
do{
?>
<tr align="left" bgcolor="#FFFFFF">
<td height="20" align="center"><?php echo $info[id]; ?></td>
<td> <?php echo $info[bookname];?></td>
<td> <?php echo $info[issuDate];?></td>
<td align="center"> <?php echo $info[price];?></td>
<td> <?php echo $info[maker];?></td>
<td> <?php echo $info[publisher];?></td>
</tr>
<<?php
}while ($info=mysqli_fetch_array($sql,MYSQLI_ASSOC));
?>
</table>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
<title>这是我的第一个php程序</title>
</head>
<body>
<form name="myform" method="post" action="">
<table width="605" border="1" cellpadding="1" bordercolor="#FF00CC" bgcolor="#CC6600">
<tr>
<td width="118" height="24" align="right" bgcolor="#0000FF">
请输入图书名称
<input name="txt_book" type="text" id="txt_book" size="25"/> </td>
<td>
<input type="submit" name="submit" value="查询"/>
</td>
</tr>
</form>
<<?php
echo "用mysql";
error_reporting(E_ALL & ~E_NOTICE);
$link=mysql_connect("localhost","root","root")or die("数据库连接失败".mysql_error());
mysql_select_db("phpmysql",$link);
$sql=mysql_query( "select * from tb_book");
if($_POST[submit]=="查询"){
$text_book=$_POST[txt_book];
//如果选择的条件为"like",则进行模糊查询
$sql=mysql_query("select * from tb_book where bookname like '%".trim($text_book)."%'");
$info=mysql_fetch_array($sql);
}
if($info==false){
echo "<div align='center' style='color:#FF0000;font-size:12px'>对不起,您检索的图书信息不存在!</div> ";
}
do{
?>
<tr align="left" bgcolor="#FFFFFF">
<td height="20" align="center"><?php echo $info[id]; ?></td>
<td> <?php echo $info[bookname];?></td>
<td> <?php echo $info[issuDate];?></td>
<td align="center"> <?php echo $info[price];?></td>
<td> <?php echo $info[maker];?></td>
<td> <?php echo $info[publisher];?></td>
</tr>
<<?php
}while ($info=mysql_fetch_array($sql));
//关闭结果集
mysql_free_result($sql);
//关闭连接
mysql_close($link);
?>
</table>
</body>
</html>