Posted By

tylerhall on 11/30/-1


Tagged

paging records pages


Versions (?)

Who likes this?

28 people have marked this snippet as a favorite

luman
katxorro70
shamrog12
millisami
blakeb
fael
vali29
hudge
JimiJay
mb
ibomb
romanos
shii
irishsk
delarge
Hollow
thejared
franverona
tapdrup
nb109
kaartz
osirisinternet
bobbym245
melihbuyuk
tspitzr
Gordy
uberdragon
Some0ne


Paging Display


 / Published in: PHP
 

  1. $db->query("SELECT COUNT(*) FROM snippets s WHERE s.user_id = '$user_id'");
  2. $numRecords = mysql_result($db->result, 0, 0);
  3. $numPages = ceil($numRecords / $perpage);
  4. $page = intval($_GET['page']);
  5. if($page > $numPages) $page = $numPages;
  6. if($page < 1) $page = 1;
  7. $start = ($page - 1) * $perpage;
  8.  
  9. $nextPage = ($page + 1 > $numPages) ? $numPages : $page + 1;
  10. $prevPage = ($page - 1 < 1) ? 1 : $page - 1;
  11.  
  12. if($page == 1 && $numPages == 1)
  13. $paging = "[Page 1 of $numPages]";
  14. elseif($page == 1 && $numPages > 1)
  15. $paging = "[Page 1 of $numPages] <a href='/users/$username/page/$nextPage'>Next »</a>";
  16. elseif($page == $numPages)
  17. $paging = "<a href='/users/$username/page/$prevPage'>« Prev</a> [Page $page of $numPages]";
  18. else
  19. $paging = "<a href='/users/$username/page/$prevPage'>« Prev</a> [Page $page of $numPages] <a href='/users/$username/page/$nextPage'>Next »</a>";

Report this snippet  

You need to login to post a comment.