2015-01-21 83 views
0

我查詢,但沒有顯示。如何查詢結果與分頁SQL服務器和PHP

請檢查我的語法。

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')後的結果沒有顯示

+0

沒有人在這裏檢查語法你說什麼你的問題 – 2015-01-21 07:30:58

+0

'LIMIT'是你的答案 – Class 2015-01-21 07:31:03

+0

@Class,SQL Server中沒有LIMIT子句 – Ishamael 2015-01-21 07:35:24

回答

0

參觀此link.You會找到答案。

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

你只需要簡單地包括這個類在你的PHP page.After是

//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. 
+0

雖然這個鏈接可能回答這個問題,但最好在這裏包含答案的重要部分並提供供參考的鏈接。 如果鏈接頁面更改,則僅鏈接答案可能會失效。 – Ghost 2015-01-21 07:41:44

+0

好吧,我解釋。感謝您的意見。 – 2015-01-21 07:43:10

+0

問題是關於MS SQL Server而不是MySQL,所以'mysql_fetch_assoc'在這裏不起作用。恕我直言,你應該用'mssql_fetch_assoc'替換它 – 2015-01-21 11:56:31