php - paging with sql srv -


i have found following code show 25 persons on every page. shows pagenumbers on top of page depending of results.

eksempel: 1 2 3 4 5 6 7 8 9 10 osv.

but this: example: 1 2 3 4 5 next

if click on "5" example: forrige 3 4 5 6 7 næste

has "ceil" function do?

$conn = sqlsrv_connect("localhost", array("database"=>"test", "uid"=>"test", "pwd"=>"test"));  $rowsperpage = 25;  $tsql = "select count(id) persons";  $stmt = sqlsrv_query($conn, $tsql);  $rowsreturned = sqlsrv_fetch_array($stmt); if($rowsreturned === false) { echo "error in retrieving number of rows."; die( print_r( sqlsrv_errors(), true)); }  elseif($rowsreturned[0] == 0) { echo "no rows returned."; } else {      $numofpages = ceil($rowsreturned[0]/$rowsperpage); for($i = 1; $i<=$numofpages; $i++) {     $pagenum = "?pagenum=$i";      if ($_get["pagenum"] == $i)      {     print("<a href=$pagenum><b>$i</b></a>&nbsp;&nbsp;");     }     else     {     print("<a href=$pagenum>$i</a>&nbsp;&nbsp;");     } } echo "<br/><br/>"; }   $tsql = "select *          (select row_number() over(order id)                      rownumber,                          firstname,                             surname     persons)     temp     rownumber between ? , ?";  if(isset($_get['pagenum'])) { $highrownum = $_get['pagenum'] * $rowsperpage; $lowrownum = $highrownum - $rowsperpage + 1; } else { $lowrownum = 1; $highrownum = $rowsperpage; }  $params = array(&$lowrownum, &$highrownum);  $stmt2 = sqlsrv_query($conn, $tsql, $params); if($stmt2 === false)  { echo "error in query execution."; die( print_r( sqlsrv_errors(), true)); }  print("<table border='1px'>     <tr>         <td>row number</td>         <td>product name</td>         <td>product id</td>     </tr>");  while($row = sqlsrv_fetch_array($stmt2) ) { print("<tr>         <td>$row[0]</td>         <td>$row[1]</td>         <td>$row[2]</td>       </tr>");  }  print("</table>"); 


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -