在搜索ajax中分页

时间:2019-08-16 01:15:41

标签: php html ajax

我的分页在 Ajax 中不起作用,当到达10个数据时,我无法在下一页或下一个数据中获取。 我想了解更多有关Ajax的信息。

预先感谢

<?php
require '../conn.php';
session_start();
$output = '';
$results_per_page = 10;
$query = "SELECT * FROM client_info WHERE status='NO' && 
w_id='".$_SESSION['wid']."' ORDER BY date asc ";
$result1 = mysqli_query($con, $query);
$number_of_results = mysqli_num_rows($result1);
$number_of_pages = ceil($number_of_results/10);

if (!isset($_GET['page'])) {
 $page = 1;
} else {
$page = $_GET['page'];
}
$this_page_first_result = ($page-1)*10;
if(isset($_POST["query"]))
{

$search = mysqli_real_escape_string($con, $_POST["query"]);
$query = "SELECT * FROM client_info INNER JOIN zipcodes ON 
client_info.loc_id = zipcodes.id INNER JOIN category ON 
client_info.cat_id 
= category.c_id  WHERE status='NO' && w_id='".$_SESSION['wid']."' && 
track_no LIKE '%".$search."%' OR fname LIKE '%".$search."%' && 
status='NO' 
&& w_id='".$_SESSION['wid']."' OR lname LIKE '%".$search."%' && 
status='NO' && w_id='".$_SESSION['wid']."' ORDER BY date asc LIMIT 
 ".$this_page_first_result." ,".$results_per_page."";

}
else
{
$query = "
SELECT * FROM client_info INNER JOIN zipcodes ON client_info.loc_id = 
zipcodes.id INNER JOIN category ON client_info.cat_id = category.c_id  
WHERE status='NO' && w_id='".$_SESSION['wid']."'  ORDER BY date asc LIMIT 
".$this_page_first_result." ,".$results_per_page."";
}
$result = mysqli_query($con, $query);
if(mysqli_num_rows($result) > 0)
{
$output .= '<div class="table-responsive">
              <table class="table" border="0">
                <thead class=" text-primary">
                  <th>
                  </th>
                  <th>
                    Name
                  </th>
                  <th>
                   Contact #
                  </th>
                  <th>
                    City
                  </th>
                   <th>
                    Plate Number
                  </th>
                  <th>
                    Category
                  </th>
                  <th>
                    Tracking #
                  </th>
                  <th>
                    Date
                  </th>

                  <th>
                    Time
                  </th>
                  <th class="text-right">
                    Action
                  </th>

                </thead>
                <tbody>';
while($row = mysqli_fetch_array($result))
{
     $createDate = new DateTime($row['date']);
                $time = $row['date'];
                $strip = $createDate->format('Y-m-d');
                $time = date("H:i:s",strtotime($time));
    $output .= "<tr>
                  <form method='POST' action='spam.php? 
  id=".$row['client_id']."'>

                    <td><input name = 'checkbox[]' type='checkbox'   
 value='".$row['client_id']."'>
                    <input name ='do' type='hidden'   ></td>
                    <td><a href='compute.php? 
  cid=".$row['client_id']."'>".$row['fname']." ".$row['lname']."</a></td>
                    <td>".$row['mobile']."</td>
                    <td>".$row['major_area'].",".$row['city']."</td>
                    <td>".$row['plate_no']."</td>
                    <td>".$row['c_name']."</td>
                    <td>".$row['track_no']."</td>
                    <td>".$strip."</td>
                    <td>".$time."</td>
                    <td class='text-right'><a href='spam.php? 
  done1=".$row['client_id']."' class='btn btn-success' >DONE</a>
                    <a href='spam.php?spam1=".$row['client_id']."' 
 class='btn btn-danger' >SPAM</a></td>
                  <tr>"

    ;
}

echo $output."<tr>

                    <td colspan='9'><hr 
 style='height:1px;border:none;color:#333;background-color:#333;''></td>
                    <td  class='text-right'><input href='#' class='btn 
 btn-success' id='done' name='done' type='submit' value='Done'><input 
 href='#' class='btn btn-danger' id='spam' name='spam' type='submit' 
 value='Spam'></td>
                  </form>
                  </tr>
                   <tr>

                      <td colspan='10'>
                       <nav aria-label='Page navigation example'>
                               <ul class='pagination'>";
        for ($page=1;$page<=$number_of_pages;$page++) {

                      echo "<li class='page-item'><a class='page-link' 
 href='dashboard.php?page=" . $page . "'>".$page."</a></li>";
                      }              


     echo"                           </ul>
                        </nav>
                     </td>
                    </tr>";
}
else
{
echo 'Data Not Found';
}
?>

我是Ajax的新手,我尝试了将近6个小时的所有工作,但我仍然不知道该怎么做才能在Ajax中进行搜索,我唯一的问题是分页。

这是用户界面enter image description here

这是dashboard.php中的Ajax代码

<script>
$(document).ready(function(){
load_data();
 function load_data(query)
 {
$.ajax({
  url:"fetch.php",
  method:"post",
  data:{query:query},
  success:function(data)
  {
    $('#result').html(data);
  }
  });
  }

  $('#search_text').keyup(function(){
  var search = $(this).val();
  if(search != '')
  {
  load_data(search);
  }
  else
  {
  load_data();      
  }
  });
  });
  </script>

0 个答案:

没有答案