Php mysql\u num\u rows()不是有效的资源-mysql\u error()不显示任何内容

Php mysql\u num\u rows()不是有效的资源-mysql\u error()不显示任何内容,php,mysql,Php,Mysql,我有以下代码 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

我有以下代码

    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!";
    }
mysql\u error()
实际上什么也没有返回,所以我对错误是什么感到非常困惑。回显时的SQL:

SELECT * FROM Products P, Manufacturers M WHERE M.sManufacturerCode='216E3ACAC673DE0260083B5FF809B102B3EC' AND M.iManufacturerID=P.iManufacturerID
我在这里很困惑!我是不是忽略了一些简单的事情

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

编辑-我正在学习教程

$rs
是一个MySQL结果资源,可用于
MySQL\u num\u rows

$pager = new PS_Pagination( $conn, $sql, 3, 4, null );    
$rs = $pager->paginate(); 
现在不是1

哎呀



1或者,如果是这样的话,[a]您没有在您的问题中向我们展示这一点,并且[b]原始查询完全没有意义。

您正在覆盖$rs变量

我猜无论
PS_分页
类在做什么,它都不会返回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(); 

我们不知道您的
$rs
变量包含什么…这部分是问题所在,我查看了lib/ps_pagination.php文件并取出了“检查数据库连接是否有效”区块。。。现在它工作得很好!谢谢大家的帮助
$pager = new PS_Pagination( $conn, $sql, 3, 4, null );    
$rs = $pager->paginate(); 
$num = mysql_num_rows( $rs ) or die('Database Error: ' . mysql_error());
$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();