Guest User

Untitled

a guest
Nov 26th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2.  
  3. <html lang="en-US">
  4.  
  5. <head>
  6.  
  7. <meta charset="UTF-8">
  8.  
  9. <title></title>
  10. <script src="bootstrap/js/bootstrap.js"></script>
  11. <link rel="stylesheet" href="bootstrap/css/bootstrap.css">
  12.  
  13. <body>
  14. <?php
  15. //connect to database
  16. $db_host = 'localhost'; // Your Host path
  17. $db_username = 'root'; // Your MYSQL Username.
  18. $db_password = ''; // Your MYSQL Password.
  19. $db_name = 'ztest'; // Your Database name.
  20.  
  21. $con = @mysqli_connect($db_host, $db_username, $db_password,$db_name)or die('Error: Could not connect to database.');
  22.  
  23. //define how many results you want per page
  24. $results_per_page =5;
  25.  
  26. //find out the number of results stored in database
  27. $sql="SELECT * FROM paging";
  28. $result = mysqli_query($con, $sql);
  29. $number_of_results = mysqli_num_rows($result);
  30.  
  31. //while($row = mysqli_fetch_array($result)){
  32. // echo $row['id'].''.$row['name'].'<br>';
  33. //}
  34.  
  35. //determine number of total pages available
  36. $number_of_pages=ceil($number_of_results/$results_per_page);
  37.  
  38. //detemine which page number visitor is currently on
  39. if(!isset($_GET['page'])){
  40. $page=1;
  41. }else{
  42. $page=$_GET['page'];
  43. }
  44.  
  45. //determine the sql LIMIT starting number for the result on the displaying page
  46. $this_page_first_result=($page-1)*$results_per_page;
  47.  
  48. //retrive selected results from database and display them on page
  49. $sql="SELECT * FROM paging LIMIT .$this_page_first_result.','.$results_per_page";
  50. $result= mysqli_query($con, $sql);
  51.  
  52. while($row=mysqli_fetch_array($result))
  53. {
  54. echo $row['id'].''.$row['name'].'<br>';
  55. }
  56.  
  57. //display the link to the pages
  58. for ($page=1;$page<=$number_of_pages;$page++){
  59. echo '<a href="index.php?page='.$page.'">'.$page.'</a>';
  60. }
  61. ?>
  62.  
  63. </body>
  64.  
  65. </html>
Add Comment
Please, Sign In to add comment