Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML>
- <html lang="en-US">
- <head>
- <meta charset="UTF-8">
- <title></title>
- <script src="bootstrap/js/bootstrap.js"></script>
- <link rel="stylesheet" href="bootstrap/css/bootstrap.css">
- <body>
- <?php
- //connect to database
- $db_host = 'localhost'; // Your Host path
- $db_username = 'root'; // Your MYSQL Username.
- $db_password = ''; // Your MYSQL Password.
- $db_name = 'ztest'; // Your Database name.
- $con = @mysqli_connect($db_host, $db_username, $db_password,$db_name)or die('Error: Could not connect to database.');
- //define how many results you want per page
- $results_per_page =5;
- //find out the number of results stored in database
- $sql="SELECT * FROM paging";
- $result = mysqli_query($con, $sql);
- $number_of_results = mysqli_num_rows($result);
- //while($row = mysqli_fetch_array($result)){
- // echo $row['id'].''.$row['name'].'<br>';
- //}
- //determine number of total pages available
- $number_of_pages=ceil($number_of_results/$results_per_page);
- //detemine which page number visitor is currently on
- if(!isset($_GET['page'])){
- $page=1;
- }else{
- $page=$_GET['page'];
- }
- //determine the sql LIMIT starting number for the result on the displaying page
- $this_page_first_result=($page-1)*$results_per_page;
- //retrive selected results from database and display them on page
- $sql="SELECT * FROM paging LIMIT .$this_page_first_result.','.$results_per_page";
- $result= mysqli_query($con, $sql);
- while($row=mysqli_fetch_array($result))
- {
- echo $row['id'].''.$row['name'].'<br>';
- }
- //display the link to the pages
- for ($page=1;$page<=$number_of_pages;$page++){
- echo '<a href="index.php?page='.$page.'">'.$page.'</a>';
- }
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment