2011-09-09 34 views
-5

我有以下代码。mysql_num_rows()不是一个有效的资源 - mysql_error()什么也没有显示

include("DBHeader.inc.php"); 
    include("libs/ps_pagination.php"); 

    $sql = "SELECT * FROM Products P, Manufacturers M WHERE M.sManufacturerCode='$LC' AND M.iManufacturerID=P.iManufacturerID"; 
    $rs = mysql_query($sql); 
    echo $sql; 

    $pager = new PS_Pagination($conn, $sql, 3, 4, null); 
    $rs = $pager->paginate(); 
    $num = mysql_num_rows($rs) or die('Database Error: ' . mysql_error()); 
    if ($num >= 1) { 
     echo "<table border='0' id='tbProd' class='tablesorter' style='width:520px;'> 
     <thead> 
      <tr> 
       <th>Product Code</th> 
       <th>Product Name</th> 
       <th> &nbsp; </th> 
      </tr> 
     </thead> 
     <tbody>"; 

     //Looping through the retrieved records 
     while($row = mysql_fetch_array($rs)) 
     { 
      echo "<tr class='prodRow'>"; 
      echo "<td>" . $row['sProductCode'] . "</td>"; 
      echo "<td>" . $row['sProductName'] . "</td>"; 
      echo "<td><a href='ProdEdit.php?=" . $row['sProductCode'] . "'><img src='images/manage.gif' alt='Edit " . $row['sProductName'] . "' /></a></td>"; 
      echo "</tr>"; 
     } 
     echo "</tbody></table>"; 
    } 
    else { 
     //if no records found 
     echo "No records found!"; 
    } 

,而不是它给我从表中数据,它吐出来在屏幕上:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/nyksys/www/regserver2/search_results.php on line 37 

mysql_error()实际上返回什么都没有,所以我以很迷茫什么错误是。 echo'd时的SQL:

SELECT * FROM Products P, Manufacturers M WHERE M.sManufacturerCode='216E3ACAC673DE0260083B5FF809B102B3EC' AND M.iManufacturerID=P.iManufacturerID 

我在这里感到莫名其妙!我在这里忽略简单的东西吗?

我已经仔细检查了我的数据库信息,我确定这不是问题。

编辑 - 我正在按照教程Paginating Your Data with AJAX and Awesome PHP Pagination Class

+0

我们不知道你的'$ rs'变量包含... – Neal

回答

2
$sql = "SELECT * FROM Products P, Manufacturers M WHERE M.sManufacturerCode='$LC' AND M.iManufacturerID=P.iManufacturerID"; 
$rs = mysql_query($sql); 
echo $sql; 

$rs是,你可以用mysql_num_rows使用MySQL结果资源。

$pager = new PS_Pagination($conn, $sql, 3, 4, null);  
$rs = $pager->paginate(); 

现在不是!

$num = mysql_num_rows($rs) or die('Database Error: ' . mysql_error()); 

哎呀!


或者,如果是,[A]你没有告诉我们,你的问题,和[B]原来的查询是完全没有意义的。

+0

这部分是问题,我看着的lib/ps_pagination.php文件,并拿出“请检查数据库连接是否有效“块...现在它完美的工作! 谢谢大家的帮助 – kogh

0

要覆盖$ RS变量

0

我的猜测是无论PS_Pagination类是干什么的,它没有返回一个MySQL的资源。您正在用该对象覆盖您的$rs资源变量,即使您的查询成功,它也不再是有效的资源。

$rs = mysql_query($sql); 
echo $sql; 

$pager = new PS_Pagination($conn, $sql, 3, 4, null); 

// Use a different variable than $rs here. 
$rs = $pager->paginate(); 
相关问题