我有以下代码。
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> </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()
实际上什么都没有返回,所以我对错误是什么感到困惑。回声时的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 :(得分: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结果资源,可以与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]原始查询完全没有意义。
答案 1 :(得分:0)
您正在覆盖$ rs变量
答案 2 :(得分: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();