Advertisement
gitlez

YA: Simple Pagenation Pg Saving GET vars

Apr 13th, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1. <?php
  2. // In response to a Yahoo Answer's Question
  3.  
  4. if(!isset($_GET['pg'])){
  5.     $_GET['pg'] = 50;
  6. }
  7.  
  8. function urlVarsMod($name, $value){
  9.     $g = $_GET;
  10.     $g[$name] = $value;
  11.     return http_build_query($g);
  12. }
  13.  
  14. // Basic Example to show you how to do so
  15. echo '<a href="?' . urlVarsMod('pg',($_GET['pg'] - 1)) . '">Prev</a> [' . $_GET['pg'] . '] <a href="?' . urlVarsMod('pg', ($_GET['pg'] + 1) ) . '">Next</a>';
  16.  
  17.  
  18. echo '<h3>Current Page: ' . $_GET['pg'] . '</h3>';
  19. echo '<p>Go Ahead, place some variables in the URL, test away</p>';
  20. echo '<table border="1" cellpadding="5"><tr><th>Name</th><th>Value</th></tr>';
  21. foreach($_GET as $n=>$v){
  22.     echo '<tr><td>' . $n . '</td><td>' . $v . '</td></tr>';
  23. }
  24. echo '</table>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement