>  기사  >  백엔드 개발  >  PHP+MySQL은 mysql_num_rows를 사용하여 퍼지 질의서 정보 기능을 구현합니다.

PHP+MySQL은 mysql_num_rows를 사용하여 퍼지 질의서 정보 기능을 구현합니다.

不言
不言원래의
2018-05-31 14:45:551518검색

이 기사에서는 퍼지 쿼리북 정보 기능을 구현하기 위해 PHP + MySQL mysql_num_rows을 소개합니다. 이는 퍼지 쿼리에 mysql의 like 쿼리 문을 사용하고 구조적 통계에 mysql_num_rows를 사용하는 것을 참조할 수 있습니다.

이 기사의 예에서는 책 정보에 대한 퍼지 쿼리 기능을 실현하기 위해 PHP+MySQL에서 mysql_num_rows를 사용하는 방법을 설명합니다. 참조를 위해 모든 사람과 공유하세요. 세부 사항은 다음과 같습니다.

1. 코드

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>应用mysql_num_rows()函数获取查询结果集中的记录数</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"><p align="center">请输入图书名称
     <input name="txt_book" type="text" id="txt_book" size="25" >
      
     <input type="submit" name="Submit" value="查询">
   </p></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("数据库连接失败".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 &#39;%".trim($txt_book)."%&#39;"); //如果选择的条件为"like",则进行模糊查询
          $info=mysql_fetch_object($sql);
        }
        if($info==false){ //如果检索的信息不存在,则输出相应的提示信息
          echo "<p align=&#39;center&#39; style=&#39;color:#FF0000; font-size:12px&#39;>对不起,您检索的图书信息不存在!</p>";
        }
        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>
             找到相关记录 <?php $nums=mysql_num_rows($sql);echo $nums;?> 条    </td>
    </tr>
   </table>
  <br></td>
 </tr>
</table>
</body>
</html>

2. 실행 결과

참고: mysql_num_rows( ) 결과 집합의 행 수를 반환합니다. 이 명령은 mysql_num_rows() 返回结果集中行的数目。此命令仅对 SELECT 语句有效。要取得被 INSERTUPDATE 或者 DELETE 查询所影响到的行的数目,需要使用 <a href="http://www.php.cn/wiki/1162.html" target="_blank">mysql_affected_rows</a>()SELECT

문에만 유효합니다.

INSERT

, UPDATE

또는 DELETE

을 받으려면 영향을 받은 행 수를 쿼리하려면 <a href="http://www.php.cn/wiki/1162.html" target="_blank">mysql_affected_rows🎜()</a>을 사용해야 합니다. . 🎜🎜관련 추천: 🎜🎜🎜 [토론] php+mysql🎜🎜🎜🎜🎜🎜에서 저장 프로시저를 사용할 때의 장점과 단점에 대해 이야기해 보겠습니다.

위 내용은 PHP+MySQL은 mysql_num_rows를 사용하여 퍼지 질의서 정보 기능을 구현합니다.의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.