我正在尝试将两个表与 INNER JOIN 连接在一起,并使用 ROW_NUMBER 限制每页显示的结果数量:
$tsql = "SELECT *
FROM (SELECT ROW_NUMBER() OVER(ORDER BY productID) AS
rownum, * FROM products INNER JOIN product_catalogue ON products.catalogueID = product_catalogue.catalogueID
WHERE category1 = '1') AS products1
WHERE rownum >= 0 AND rownum <= 6";
$stmt = sqlsrv_query($conn,$tsql);
while($row = sqlsrv_fetch_array($stmt)){
echo $row['productID']. "<br/>";
echo $row['product_name']. "<br/>";
}
我收到“sqlsrv_fetch_array() 期望参数 1 是资源”错误,并且我知道这与使用 INNER JOIN 的我有关,因为如果我在没有它的情况下运行查询,我的页面上会显示结果:
$tsql = "SELECT *
FROM (SELECT ROW_NUMBER() OVER(ORDER BY productID) AS
rownum, * FROM products ) AS products1
WHERE rownum >= 0 AND rownum <= 6";