-1

index.php:

<script>
$(document).ready(function(){
  $("#submit2").click(function(){
    course = $("#courses").val();
    field2 = $("#field2").val();
    $("#imagen").show();
    $.ajax({
      type:"POST",
      data:{"courses":course,"field2":field2},
      url:"college.php",
      success:function(data){
        $("#imagen").hide();
        $("#popular_colleges").html(data);
      }
    });
  });
});
</script>

<img id="imagen" src="please.gif">
<div id ="popular_colleges"></div>

college.php

<?php
  $course = $_POST['courses'];
  $field2 = $_POST['field2'];
  $per_page=10;
  if (isset($_GET["page"])) 
  {
  $page = $_GET["page"];
  }
  else {
  $page=1;
  }
  $start_from = ($page-1) * $per_page;
  $sql = "select * from college where course like '%,$course,%' LIMIT $start_from, $per_page";
  $result = mysqli_query($link,$sql);
  while($row = mysqli_fetch_array($result))
  {
      echo $row['logo'];
      echo $row['collegename'];
      echo $row['stream'];
  }
?>

<?php
  $query = "select * from colleges";
  $result = mysqli_query($link, $query);
  $total_records = mysqli_num_rows($result);
  $total_pages = ceil($total_records / $per_page);
  echo "<center><a href='index.php?page=1' style='padding:10px;'>".'First Page'."</a>";
  $skipped = false;
    for ($i = 1; $i <= $total_pages; $i++)  {
        if ($i < 3 || $total_pages- $i < 3 || abs($page - $i) < 3) {
            if ($skipped)
                echo '<span> ... </span>';
            $skipped = false;
            echo "<a href='index.php?page=" . $i . "' style='padding:5px;'>" . $i . "</a>";
        } else {
            $skipped = true;
        }
    }
  echo "<a href='index.php?page=$total_pages' style='padding:10px;'>".'Last Page'."</a></center>";
  ?>

In this code when I click on submit2 button it showing pagination but when I click on any pagination number it will reload the same page but I want that when clicking on pagination number don't load the page and showing the result on the same page.

enter image description here

kevin
  • 234
  • 2
  • 14

1 Answers1

0

index.php?page=, but you are not doing anything with page variable in index.php. As I can see you are using it in college.php, but college.php doesn't receive page variable.

You are sending a POST request and trying to get page from $_GET. You can only have one verb (POST, GET, PUT, ...) when doing an HTTP Request.

You are sending data through AJAX to college.php.

data:{"courses":course,"field2":field2}

As you can see, you are not sending page. You need to send page as well.

data:{"courses":course,"field2":field2, "page": page}

And use $_POST['page'] instead of $_GET['page']

Jurij Jazdanov
  • 1,248
  • 8
  • 11
  • as you say I am send data:{"courses":course,"field2":field2, "page": page} and also use $_POST['page '] instead of $_GET['page'] but it show nothing. @jurij – kevin May 24 '17 at 09:49
  • putting page with out initializing it won't do anything. You need to get the value of a page onclick with javascript. that will need some programming. I can point where is the problem but I won't code for you. – Jurij Jazdanov May 24 '17 at 09:57