首页上一页 1 下一页尾页 1 条记录 1/1页
PHP从入门到精通18\3,想在文本域上方输出一个判断的内容,请看我代码,//注释部分是我想在那实现的,可是不成功,怎么办?
发表在PHP图书答疑
2010-07-28
是否精华
是
否
版块置顶:
是
否
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="style.css" rel="stylesheet">
<title>应用mysql_fetch_array()函数从数组结果集中获取信息</title>
<style type="text/css">
<!--
#Layer1 {
position:absolute;
left:219px;
top:14px;
width:607px;
height:16px;
z-index:1;
}
-->
</style>
</head>
<body>
<table width="609" height="171" border="1" cellpadding="0" cellspacing="0" bgcolor="#9E7DB4" align="center">
<form name="myform" method="post" action="">
<tr>
<td height="24" bgcolor="#CC99FF"><div align="center"><?php function upint(){
global $k;
echo "请输入要查询的内容";
}
//如果txt_book为空,提示请输入要查询的内容,如果不为空就不输出,请问怎么处理??
?></div>
</td>
</tr>
<tr>
<td width="605" height="51" bgcolor="#CC99FF"><div align="center">请输入图书名称
<input name="txt_book" type="text" id="txt_book" size="25" >
<input type="submit" name="submit" value="查询">
</div></td>
</tr>
</form>
<tr valign="top" bgcolor="#FFFFFF">
<td height="81">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="79" align="center" valign="top"> <br>
<table width="572" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#625D59">
<tr align="center" bgcolor="#CC99FF">
<td width="46" height="20">编号</td>
<td width="167">图书名称</td>
<td width="90">出版时间</td>
<td width="70">图书定价</td>
<td width="78">作者</td>
<td width="114">出版社</td>
</tr>
<?php
$link=mysql_connect("localhost","root","root") or die("数据库连接失败".mysql_error());
mysql_select_db("db_database18",$link);
mysql_query("set names gb2312");
if($_POST[txt_book]==""){
return upint();
}
else if($_POST[submit]=="查询"){
$txt_book = $_POST[txt_book];
$sql = mysql_query("select * from tb_book where bookname like '%".trim($txt_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 align="center"><?php echo $info[issuDate];?></td>
<td align="center"><?php echo $info[price];?></td>
<td align="center"><?php echo $info[maker];?></td>
<td><?php echo $info[publisher];?></td>
</tr><?php }while($info=mysql_fetch_array($sql));
?>
</table>
</td>
</tr>
</table>
<br></td>
</tr>
</table>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="style.css" rel="stylesheet">
<title>应用mysql_fetch_array()函数从数组结果集中获取信息</title>
<style type="text/css">
<!--
#Layer1 {
position:absolute;
left:219px;
top:14px;
width:607px;
height:16px;
z-index:1;
}
-->
</style>
</head>
<body>
<table width="609" height="171" border="1" cellpadding="0" cellspacing="0" bgcolor="#9E7DB4" align="center">
<form name="myform" method="post" action="">
<tr>
<td height="24" bgcolor="#CC99FF"><div align="center"><?php function upint(){
global $k;
echo "请输入要查询的内容";
}
//如果txt_book为空,提示请输入要查询的内容,如果不为空就不输出,请问怎么处理??
?></div>
</td>
</tr>
<tr>
<td width="605" height="51" bgcolor="#CC99FF"><div align="center">请输入图书名称
<input name="txt_book" type="text" id="txt_book" size="25" >
<input type="submit" name="submit" value="查询">
</div></td>
</tr>
</form>
<tr valign="top" bgcolor="#FFFFFF">
<td height="81">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="79" align="center" valign="top"> <br>
<table width="572" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#625D59">
<tr align="center" bgcolor="#CC99FF">
<td width="46" height="20">编号</td>
<td width="167">图书名称</td>
<td width="90">出版时间</td>
<td width="70">图书定价</td>
<td width="78">作者</td>
<td width="114">出版社</td>
</tr>
<?php
$link=mysql_connect("localhost","root","root") or die("数据库连接失败".mysql_error());
mysql_select_db("db_database18",$link);
mysql_query("set names gb2312");
if($_POST[txt_book]==""){
return upint();
}
else if($_POST[submit]=="查询"){
$txt_book = $_POST[txt_book];
$sql = mysql_query("select * from tb_book where bookname like '%".trim($txt_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 align="center"><?php echo $info[issuDate];?></td>
<td align="center"><?php echo $info[price];?></td>
<td align="center"><?php echo $info[maker];?></td>
<td><?php echo $info[publisher];?></td>
</tr><?php }while($info=mysql_fetch_array($sql));
?>
</table>
</td>
</tr>
</table>
<br></td>
</tr>
</table>
</body>
</html>