mysql_num_rows()不是有效的资源-mysql_error()没有显示任何内容


mysql_num_rows() not a valid resource - mysql_error() shows nothing

我有以下代码。

    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()实际上根本没有返回任何内容,所以我很困惑错误是什么

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

我在这里很困惑!我是不是忽略了一些简单的东西?

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

编辑-我正在遵循教程用AJAX和真棒PHP分页类分页您的数据

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

$rs是一个MySQL结果资源,可以与mysql_num_rows一起使用。

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

现在它不是1

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

哎呀!


1或者,如果是的话,[a]你在问题中没有向我们展示这一点,而[b]最初的查询完全没有意义。

您正在覆盖$rs变量

我的猜测是,无论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();