I need some help. I get error when my page count is 0 "Start page option is incorrect"
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 by 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);
Thank you in advance.
I've solved a similar issue base 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});
JQuery TwbsPagination
will return this error if below condition became 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 always will see this error. (startpage
option does not matter)
I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With