PHP+MySQL使用mysql_num_rows實現(xiàn)模糊查詢圖書信息功能
本文實例講述了PHP+MySQL使用mysql_num_rows實現(xiàn)模糊查詢圖書信息功能。分享給大家供大家參考,具體如下:
一、代碼
td{
font-size:9pt;
}
.style2 {color: #FFFFFF}
<!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="external nofollow" rel="stylesheet">
<title>應(yīng)用mysql_num_rows()函數(shù)獲取查詢結(jié)果集中的記錄數(shù)</title>
</head>
<body>
<table width="609" height="134" border="1" cellpadding="0" cellspacing="0" bgcolor="#9E7DB4" align="center">
<form name="myform" method="post" action="">
<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="right" 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("數(shù)據(jù)庫連接失敗".mysql_error());
mysql_select_db("db_database13",$link);
mysql_query("set names gb2312");
$sql=mysql_query("select * from tb_book");
$info=mysql_fetch_object($sql);
if ($_POST[Submit]=="查詢"){
$txt_book=$_POST[txt_book];
$sql=mysql_query("select * from tb_book where bookname like '%".trim($txt_book)."%'"); //如果選擇的條件為"like",則進行模糊查詢
$info=mysql_fetch_object($sql);
}
if($info==false){ //如果檢索的信息不存在,則輸出相應(yīng)的提示信息
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_object($sql));
?>
</table>
<br>
找到相關(guān)記錄 <?php $nums=mysql_num_rows($sql);echo $nums;?> 條 </td>
</tr>
</table>
<br></td>
</tr>
</table>
</body>
</html>
二、運行結(jié)果

注意:這里使用mysql_num_rows() 返回結(jié)果集中行的數(shù)目。此命令僅對 SELECT 語句有效。要取得被 INSERT,UPDATE 或者 DELETE 查詢所影響到的行的數(shù)目,需要使用 mysql_affected_rows()。
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php+mysql數(shù)據(jù)庫操作入門教程》、《php+mysqli數(shù)據(jù)庫程序設(shè)計技巧總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設(shè)計有所幫助。
相關(guān)文章
php使用str_replace實現(xiàn)輸入框回車替換br的方法
這篇文章主要介紹了php使用str_replace實現(xiàn)輸入框回車替換br的方法,可實現(xiàn)使用\\n替換成br的方法,需要的朋友可以參考下2014-11-11
php ob_flush,flush在ie中緩沖無效的解決方法
一些版本的 Microsoft Internet Explorer 只有當(dāng)接受到的256個字節(jié)以后才開始顯示該頁面,所以必須發(fā)送一些額外的空格來讓這些瀏覽器顯示頁面內(nèi)容。2010-05-05
PHP實現(xiàn)的AES雙向加密解密功能示例【128位】
這篇文章主要介紹了PHP實現(xiàn)的AES雙向加密解密功能,結(jié)合實例形式分析了基于AES算法的加密解密類定義與使用技巧,需要的朋友可以參考下2018-09-09
php+ajax實現(xiàn)無刷新的新聞留言系統(tǒng)
這篇文章主要介紹了一款基于php+ajax無刷新的新聞留言系統(tǒng)實現(xiàn)過程,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2015-10-10
PHP數(shù)組與對象之間使用遞歸實現(xiàn)轉(zhuǎn)換的方法
這篇文章主要介紹了PHP數(shù)組與對象之間使用遞歸實現(xiàn)轉(zhuǎn)換的方法,涉及php數(shù)組與對象的相關(guān)操作技巧,需要的朋友可以參考下2015-06-06

