Invalid start page parameter with two lines

I need help. I get an error when the page count is 0. "Invalid home page page"

here is my code

$rows = $employee->countData($param);
$per_page = 5;
$pages = ceil( $rows / $per_page );

      

the value of $ pages is 0

This is how I get the pages using jquery.ajax

var total_pages = data;
var logid = '30';

$('#pagination')
  .empty()
  .removeData("twbs-pagination")
  .unbind("page");

$('#pagination').twbsPagination({

  totalPages: total_pages,
  visiblePages: 7,
  onPageClick: function (event, page) {
      $('#container').load('load_data.php',{page:page,id:logid});
  }
});

$('#container').load('load_data.php',{id:logid});

      

here is my load_data.php

$page = isset($_POST['page']) ? (int) $_POST['page'] : 1 ;

$id = $_POST['id'];

$per_page = 5;

if($page == 0)
    $start = 0;
else
    $start = ( $page - 1 ) * $per_page;


$result = $emp->getPainateData($id,$start,$per_page);

      

Thanks in advance.

+5


source to share


2 answers


I solved a similar problem based on this solution . Basically you just need to check the element for twbsPagination, and if it exists, destroy it.



var total_pages = data;
var logid = '30';

if($('#pagination').data("twbs-pagination"))
  $('#pagination').twbsPagination('destroy');


$('#pagination').twbsPagination({
  totalPages: total_pages,
  visiblePages: 7,
  onPageClick: function (event, page) {
      $('#container').load('load_data.php',{page:page,id:logid});
  }
});

$('#container').load('load_data.php',{id:logid});

      

+5


source


JQuery TwbsPagination

will return this error if the below condition becomes true:
this.options.startPage < 1 || this.options.startPage > this.options.totalPages


So, as you said "my page count is 0", this condition will always be true, so you will always see this error. (the startpage

page option is irrelevant)
Hope this helps.



0


source







All Articles