php - LIMIT command SQL Server -


this php code:

require_once ('configsql.php');  $per_page = 10; if(isset($_get['page'])) {     $page = ($_get['page'] - 1); } else {     $page = 0; }     $querycharacter = mssql_query ("         select character.accountid, character.name, character.ctlcode,          accountcharacter.number, accountcharacter.id,          memb___id, memb_name, memb__pwd2, mail_addr         character, accountcharacter, memb_info         character.accountid=accountcharacter.id ,          accountid=memb___id , accountcharacter.id=memb___id          limit {$page},{$per_page}         ");  $rows = mssql_fetch_row($querycharacter); $pages = $rows / $per_page; $pages = $pages ? ((int)$pages == $pages) : ((int)$pages + 1); 

and error:

warning: mssql_query() [function.mssql-query]: message: line 2: incorrect syntax near ','. (severity 15) in c:\xampp\htdocs\pages\editcharacter.php on line 19

warning: mssql_query() [function.mssql-query]: query failed in c:\xampp\htdocs\pages\editcharacter.php on line 19

warning: mssql_fetch_row(): supplied argument not valid ms sql-result resource in c:\xampp\htdocs\pages\editcharacter.php on line 21

i know problem 'limit' in sql query.

how 'select' need ?

try changing query this:

with paging (     select         ,character.accountid         ,character.name         ,character.ctlcode         ,accountcharacter.number         ,accountcharacter.id         ,memb___id         ,memb_name         ,memb__pwd2         ,mail_addr         ,row_number() on (order character.accountid) rownr             character,          accountcharacter,          memb_info             character.accountid = accountcharacter.id         , accountid=memb___id          , accountcharacter.id=memb___id  ) select top ({$per_page}) * paging rownr > {$page} * {$per_page} order rownr 

note page 0 first page, 1 second, etc.

this uses common table expressions introduced in mssql 2005, earlier versions, should work (source efficient paging (limit) query in sqlserver 2000?):

declare @sort int  set rowcount {$page} * {$per_page} select @sort = accountid character order accountid  set rowcount {$per_page}     select     ,character.accountid     ,character.name     ,character.ctlcode     ,accountcharacter.number     ,accountcharacter.id     ,memb___id     ,memb_name     ,memb__pwd2     ,mail_addr     ,row_number() on (order character.accountid) rownr     character,      accountcharacter,      memb_info     character.accountid > @sort     , character.accountid = accountcharacter.id     , accountid=memb___id      , accountcharacter.id=memb___id order     character.accountid 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -