Advertisement
Guest User

Untitled

a guest
Aug 13th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.24 KB | None | 0 0
  1. <?php
  2. // config-------------------------------------
  3. $host = "localhost"; //your database host
  4. $user = "USERNAME"; // your database user name
  5. $pass = "PASSWORD"; // your database password
  6. $db = "DATABASENAME"; // your database name
  7. $filename = "test.php"; // name of this file
  8. $option = array (5, 10, 25, 50, 100, 200);
  9. $default = 10; // default number of records per page
  10. $action = $_SERVER['PHP_SELF']; // if this doesn't work, enter the filename
  11. $query = "SELECT `memberName` FROM `smf_members`ORDER BY `dateRegistered`"; // database query. Enter your query here
  12. // end config---------------------------------
  13.  
  14. $opt_cnt = count ($option);
  15. $go = $_GET['go'];
  16. // paranoid
  17. if ($go == "") {
  18. $go = $default;
  19. }
  20. elseif (!in_array ($go, $option)) {
  21. $go = $default;
  22. }
  23. elseif (!is_numeric ($go)) {
  24. $go = $default;
  25. }
  26. $nol = $go;
  27. $limit = "0, $nol";
  28. $count = 1;
  29. echo "<form name=\"form1\" id=\"form1\" method=\"get\" action=\"$action\">\r\n";
  30. echo "<select name=\"go\" id=\"go\">\r\n";
  31. for ($i = 0; $i <= $opt_cnt; $i ++) {
  32. if ($option[$i] == $go) {
  33. echo "<option value=\"".$option[$i]."\" selected=\"selected\">".$option[$i]."</option>\r\n";
  34. } else {
  35. echo "<option value=\"".$option[$i]."\">".$option[$i]."</option>\r\n";
  36. }
  37. }
  38. echo "</select>\r\n";
  39. echo "<input type=\"submit\" name=\"Submit\" id=\"Submit\" value=\"Go\" />\r\n";
  40. echo "</form>\r\n";
  41. $connection = mysql_connect ($host, $user, $pass) or die ("Unable to connect");
  42. mysql_select_db ($db) or die ("Unable to select database $db");
  43.  
  44. // control query------------------------------
  45. /* this query checks how many records you have in your table.
  46. I created this query so we could be able to check if user is
  47. trying to append number larger than the number of records
  48. to the query string.*/
  49. $off_sql = mysql_query ("$query") or die ("Error in query: $off_sql".mysql_error());
  50. $off_pag = ceil (mysql_num_rows($off_sql) / $nol);
  51. //--------------------------------------------
  52. $off = $_GET['offset'];
  53. //paranoid
  54. if (get_magic_quotes_gpc() == 0) {
  55. $off = addslashes ($off);
  56. }
  57. if (!is_numeric ($off)) {
  58. $off = 1;
  59. }
  60. // this checks if user is trying to put something stupid in query string
  61. if ($off > $off_pag) {
  62. $off = 1;
  63. }
  64. if ($off == "1") {
  65. $limit = "0, $nol";
  66. }
  67. elseif ($off <> "") {
  68. for ($i = 0; $i <= ($off - 1) * $nol; $i ++) {
  69. $limit = "$i, $nol";
  70. $count = $i + 1;
  71. }
  72. }
  73.  
  74. // Query to extract records from database.
  75. $sql = mysql_query ("$query LIMIT $limit") or die ("Error in query: $sql".mysql_error());
  76. while ($row = mysql_fetch_object($sql)) {
  77.  
  78. // EDIT ME. Edit the line below to match your own table. Just replace $row->url with $row->your_table_column
  79. echo "$count. <a href=\"$row->memberName\">$row->memberName</a><br />\r\n"; // this is example, you may enter here anything you like
  80. $count += 1;
  81. }
  82. echo "<br /><br />\r\n";
  83. if ($off <> 1) {
  84. $prev = $off - 1;
  85. echo "[ < <a href=\"$filename?offset=$prev&go=$go\">prev</a> ] \r\n";
  86. }
  87. for ($i = 1; $i <= $off_pag; $i ++) {
  88. if ($i == $off) {
  89. echo "[<b> $i </b>] \r\n";
  90. } else {
  91. echo "[ <a href=\"$filename?offset=$i&go=$go\">$i</a> ] \r\n";
  92. }
  93. }
  94. if ($off < $off_pag) {
  95. $next = $off + 1;
  96. echo "[ <a href=\"$filename?offset=$next&go=$go\">next</a> > ] \r\n";
  97. }
  98. echo "<br /><br />\r\n";
  99. echo "Page $off of $off_pag<br />\r\n";
  100. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement