Closed openqubit closed 8 years ago
@openqubit - from the doco for data-pagination-side
Look at the examples: http://issues.wenzhixin.net.cn/bootstrap-table/
You can see what happens is, by default, the request url looks something like /data?order=asc&limit=10&offset=10
These param are sent and the response thats returned should match that subset of data requested.
Total is always total in DB, but just return needed subset.
If you need more help look at almost any php+mysql pagination script - exact same principle just be certain to encode and return as json that matches the format above (or use data-response-handler
to tweak return before its loaded)
From the client side this are the params being sent
limit 10
offset 0
order asc
This is my client side code
<table id="table"
data-toggle="table"
data-url="http://localhost:8080/index.php"
data-height="400"
data-side-pagination="server"
data-pagination="true"
data-page-list="[5, 10, 20, 50, 100, 200]"
data-search="true">
<thead>
<tr>
<th data-field="state" data-checkbox="true"></th>
<th data-field="id">Id</th>
<th data-field="code">Item Name</th>
<th data-field="name">Item Price</th>
</tr>
</thead>
</table>
@dabros I can get the table to display okay but its the search and pagination that are the issue.
@openqubit - what is the problem???
The actual pagination is in your server side script, nothing to do with what you are showing insofar as those param are actually sent.
ie, something like this (taken from #25)
$limit = $_GET['limit'];
$offset = $_GET['offset'];
... // http://www.tutorialspoint.com/php/mysql_select_php.htm
echo json_encode(array(
'total' => 800, // select count(*) from table ...
'rows' = $rows // select * from table limit ...
));
You still havent said what the actual issue is.
Please read my post above again and state what exactly the current output vs desired output.
@dabros The problem is that the pagination is not working. If you try running the script you will see what i mean.
@openqubit - that first never had php when i saw it, try mentioning that if you update after or close to someone posting
limit $limit,$offset";
correct to: limit $offset, $limit";
search: $search= $_GET['search'];
@openqubit - i have no active enviornment atm, even if i had your DB, so frankly i cant test that and I know the client side you copied it from works since i already showed an working example, up to you to check for consistency and console errors, or provide a fiddle.
What you need to look at is the current ouput vs desired output.
What is the ouput??
Quite obviously this means the data requests both ways, whether any console errors, and what "not working" actually means in exact details.
Is there a console error? Does running the generated sql direct produce an sql error? Is there an error msg in the data return? Is the data returning actually offset? Is the param sent being updated each time? ect.
There is no script that i can 'run' that uses all your parts.
If you want to show an example then use a fiddle: https://github.com/wenzhixin/bootstrap-table/blob/master/CONTRIBUTING.md#bug-reports
@dabros Okay sir,understood.
@wenzhixin My php script index.php
<?php
$limit = $_GET['limit'];
$offset = $_GET['offset'];
//$search = $_GET['search'];
$sql = "SELECT code,name from country order by code asc limit $offset, $limit";
function connectDB(){
$server = "localhost";
$user = "root";
$pass = "123456";
$bd = "world";
$conexion = mysqli_connect($server, $user, $pass,$bd);
return $conexion;
}
function disconnectDB($conexion){
$close = mysqli_close($conexion);
return $close;
}
function getArraySQL($sql){
$conexion = connectDB();
mysqli_set_charset($conexion, "utf8");
if(!$result = mysqli_query($conexion, $sql)) die();
$rawdata = array();
$i=0;
while($row = mysqli_fetch_array($result))
{
$rawdata[$i] = $row;
$i++;
}
disconnectDB($conexion);
return $rawdata;
}
function cr($sql){
$mysqli = new mysqli("localhost", "root", "123456", "world");
if ($result = $mysqli->query($sql)) {
$row_cnt = $result->num_rows;
return $row_cnt;
}
}
$myArray = getArraySQL($sql);
$count = cr($sql);
$test= array(
'total' => $count,
'rows' => $myArray,
);
header('Content-Type: application/json');
echo json_encode($test);
?>
and my html
<table id="table"
data-toggle="table"
data-url="http://localhost:8080/index.php"
data-height="400"
data-side-pagination="server"
data-pagination="true"
data-page-list="[5, 10, 20, 50, 100, 200]"
data-search="true">
<thead>
<tr>
<th data-field="state" data-checkbox="true"></th>
<th data-field="id">Id</th>
<th data-field="code">Item Name</th>
<th data-field="name">Item Price</th>
</tr>
</thead>
</table>
That code produces this
Notice that the pagination is missing.
@openqubit - pagination isnt showing because its reading only 10 rows as 'total' index, so as i said earlier check the data return
Bit hard to tell from script, but it looks like your using the same sql to generate total as to generate return
That will not work
It should be obvious from the data return
You need to debug by hitting F12 and monitoring this
In the first post you share json which says total 30, that cant still be true as it would then say "showing 1 to 10 of 30 rows", with pagination to the right.
Total rows query cannot have a 'limit', else ofcourse num_rows
will be broken.
@dabros I have since corrected the pagination issues i was having. Thanks for the tip.
Hello,i am selecting data from mysql database using php and i can't seem to have it working correctly. I want to use server side pagination and i am not able to know the format of the data required.
So far this is the script
The code gives this json which displays the table correctly
I need help to complete the script and also make amends on the client side if i have to to enable me have the server side pagination that i want.