mysqli_num_rows()期望参数1为mysqli_result,布尔值为

时间:2013-01-06 23:04:09

标签: php mysqli

  

可能重复:
  mysql_fetch_array() expects parameter 1 to be resource, boolean given in select
  PHP error: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given

警告:mysqli_num_rows()要求参数1为mysqli_result,在第120行的[文件的绝对路径]中给出布尔值

file =

的第120行
    $numrows = mysqli_num_rows($result);

真正令人费解的是,当我在本地计算机(PHP 5.4.7; MySQL 5.5.27)上运行页面和查询时,它运行正常并返回一个列表,就像它应该的那样。只有当文件传输到远程服务器(PHP 5.2或5.4,MySQL 5.0 - 1and1.com)并在其上运行时才能运行(我已经更改了所有数据库访问和密码!)。

我确信这是一件简单而愚蠢的事,但我很茫然!将非常感谢您的帮助!!

代码如下。

谢谢!

    <?php
    error_reporting(E_ALL);
    ini_set( 'display_errors','1'); 

    if (isset($_POST['submitted'])) {

    // connect to database
    include('../connect.php');

    $category = $_POST['category'];
    $criteria = $_POST['criteria'];
    $query = "SELECT * FROM erstallions WHERE $category LIKE '%".$criteria."%'";
    $result = mysqli_query($dbcon, $query);
    $numrows = mysqli_num_rows($result);


 // If the query has results ...
 if ($numrows > 0)
 {
     // ... print out a header
     if ($criteria == '')
     {
     print "<br /><center><font size=\"+2\"><b>Stallion Listing</b></font></center><br>";
     }
     else
     {
     print "<center><font size=\"+2\"><b>Information about the stallion '$criteria'<br>(Frozen by <i>Equine-Reproduction.com LLC</i>)</b></font></center><br>";
     };

     // and start a <table>.
     print "\n<table width=\"100%\" border=\"1\" align=\"center\">\n<tr>" .
           "\n\t<th>Stallion Name</th>" .
           "\n\t<th>Owner</th>" .
           "\n\t<th>Breed</th>" .
           "\n\t<th>Reg. Number</th>" .
           "\n\t<th>Birth Date/Year</th>\n</tr>";

     // Fetch each of the query rows
     while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) 
     {
        // Print one row of results
          print "\n<tr>\n\t<td><a href=\"StallionDetails.php?StallionName={$row["StallionName"]}\" target=\"_blank\">{$row["StallionName"]}</a></td>" .
          "\n\t<td>{$row["OwnerName"]}</td>" .
          "\n\t<td>{$row["StallionBreed"]}</td>" .
          "\n\t<td>{$row["StallionRegNo"]}</td>" .
          "\n\t<td><center>{$row["DoB"]}</center></td>\n</tr>";
     } // end while loop body

     // Finish the <table>
     print "\n</table>";
 } // end if $rowsFound body

 // Report how many rows were found
          print "<center>{$numrows} record(s) found matching your criteria</center><br>";


    } //End of main if statement

    ?>

1 个答案:

答案 0 :(得分:0)

请在此处修改您的代码:

     $query = "SELECT * FROM erstallions WHERE $category LIKE '%".$criteria."%'";

应该是

         $query = "SELECT * FROM erstallions WHERE category LIKE '%".$criteria."%'";