Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. <?php
  2.  
  3. //Getting the page number which is to be displayed
  4. $page = $_GET['page'];
  5.  
  6. //Initially we show the data from 1st row that means the 0th row
  7. $start = 0;
  8.  
  9. //Limit is 3 that means we will show 3 items at once
  10. $limit = 3;
  11.  
  12. //Importing the database connection
  13. require_once('koneksi.php');
  14.  
  15. //Counting the total item available in the database
  16. $total = mysqli_num_rows(mysqli_query($con, "SELECT id from tbl_materi "));
  17.  
  18. //We can go atmost to page number total/limit
  19. $page_limit = $total/$limit;
  20.  
  21. //If the page number is more than the limit we cannot show anything
  22. if($page<=$page_limit){
  23.  
  24. //Calculating start for every given page number
  25. $start = ($page - 1) * $limit;
  26.  
  27. //SQL query to fetch data of a range
  28. $sql = "SELECT * from tbl_materi limit $start, $limit";
  29.  
  30. //Getting result
  31. $result = mysqli_query($con,$sql);
  32.  
  33. //Adding results to an array
  34. $res = array();
  35.  
  36. while($row = mysqli_fetch_array($result)){
  37. array_push($res, array(
  38. "judul"=>$row['judul'],
  39. "gambar_materi"=>$row['gambar_materi'],
  40. "deskripsi"=>$row['deskripsi'])
  41. );
  42. }
  43. //Displaying the array in json format
  44. echo json_encode($res);
  45. }else{
  46. echo "over";
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement