如何使用分页SQL服务器和PHP查询结果

时间:2015-01-21 07:29:15

标签: php sql-server

我当时查询但没有显示。

请检查我的语法。

    SELECT TOP 100 [nUserID],[nDeviceID],[dtDateTime],[strUserName],[DeviceID],[DeviceName]
FROM 
( 
SELECT [tb_reportslist].nUserID,[tb_reportslist].nDeviceID,[tb_reportslist].dtDateTime,[DeviceID],[DeviceName],[strUserName], 
ROW_NUMBER() OVER (ORDER BY [tb_reportslist].nUserID,[tb_reportslist].nDeviceID,[tb_reportslist].dtDateTime) AS RowNumber 
FROM [hr_scan].[dbo].[tb_reportslist] INNER JOIN [hr_scan].[dbo].[imp_emp] ON tb_reportslist.nUserID = imp_emp.[nUserID] 
INNER JOIN [hr_scan].[dbo].[Device_sukishi] ON tb_reportslist.nDeviceID = Device_sukishi.[DeviceID] 
WHERE ((convert(date,[tb_reportslist].dtDateTime)) BETWEEN  '2015-01-18' AND '2015-01-20') AND ([tb_reportslist].nUserID = '572420')

) EmployeePage WHERE RowNumber BETWEEN ((10 - 1) * 10 + 1) AND (10 * 10)    

我在AND ([tb_reportslist].nUserID = '572420'之后添加语法((convert(date,[tb_reportslist].dtDateTime)) BETWEEN '2015-01-18' AND '2015-01-20')结果未显示

1 个答案:

答案 0 :(得分:0)

访问此链接。您将找到答案。

http://phpsense.com/2007/php-pagination-script/

您只需要在PHP页面中包含此类。之后

//Query to pass to pagination class
$sql = 'SELECT * FROM YourTable';

//Create a PS_Pagination object
$pager = new PS_Pagination($conn, $sql, 10, 10); 

//First 10 is for record per page 
//Second 10 is for link of pagination per page.
//You can change both as per your requirement.
//$conn is your connection variable.

//The paginate() function returns a mysql result set for the current page
$rs = $pager->paginate(); 

while($row = mssql_fetch_assoc($rs)) {
  Your Work
}

//Display the navigation
echo $pager->renderFullNav();// Use this single line where(Div,P any tag) you want to show pagination.