Advertisement
Guest User

get_data.php

a guest
Jun 10th, 2017
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1. <?php
  2.    
  3.     $servername ="localhost";
  4.     $username = "root";
  5.     $password = "";
  6.     $dbname = "produ_db";
  7.  
  8. // Create connection
  9. $conn = mysqli_connect($servername, $username, $password, $dbname);
  10. // Check connection
  11. if (!$conn) {
  12.     die("Connection failed: " . mysqli_connect_error());
  13. }
  14.     if(isset($_GET['offset']) && isset($_GET['limit'])){
  15.        
  16.         $limit = $_GET['limit'];
  17.         $offset = $_GET['offset'];
  18.        
  19.     $data = mysqli_query($conn, "SELECT * FROM `posts` LIMIT {$limit} OFFSET {$offset}");
  20.    
  21.     while($row = mysqli_fetch_array($data)) {
  22.         echo '<div class="blog-post"><h1>'.$row['id'].'</h1><p>'.$row['post'].'</p></div>';
  23.    
  24. }
  25. }
  26.    
  27. mysqli_close($conn);
  28. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement