简体   繁体   中英

“No matching records found” NOT displayed in “bootstrap-table”

I am using the "bootstrap-table"( https://github.com/wenzhixin/bootstrap-table ) plugin for my website and currently using it's server side pagination properties.

The table is being populated correctly and the search feature also works. BUT when something not present is searched for, it displays all the records instead of displaying "No matching records found".

This is the html code I am using...

<table data-toggle="table"
       data-url="1.php"
       data-pagination="true"
       data-side-pagination="server"
       data-page-list="[5, 10, 20, 50, 100, 200]"
       data-search="true"
       data-height="300">
    <thead>
    <tr>
        <th data-field="state" data-checkbox="true"></th>
        <th data-field="memberID" data-align="right" data-sortable="true">Member ID</th>
        <th data-field="name" data-align="center" data-sortable="true"> Name</th>
        <th data-field="dob" data-sortable="true">Date of Birth</th>
    </tr>
    </thead>


</table>

and this is the php script I am using to create the JSON response...

<?php

require_once('db-connect.php');

if(isset($_GET["limit"])) {
    $limit = $_GET["limit"];
} else {
    $limit = 10;
}

if(isset($_GET["offset"])) {
    $offset = $_GET["offset"];
} else {
    $offset = 0;
}

if(isset($_GET["sort"])) {
    $sort = $_GET["sort"];
} else {
    $sort = "";
}

if(isset($_GET["order"])) {
    $order = $_GET["order"];
} else {
    $order = "asc";
}

 if(isset($_GET["search"])) {
    $search = $_GET["search"];
 } else {
    $search = "";
 }


if($search == "") {
    $result = mysqli_query($connection,"select memberID, name, dob from memberdetails" );
} else {

    $result = mysqli_query($connection,"select memberID, name, dob from memberdetails WHERE memberID LIKE '%$search%'"  );
}


$row = array();

if ( mysqli_num_rows($result) > 0 ) {
            while($row = mysqli_fetch_assoc($result)) {
                $result_2d_arr[] = array (  'memberID' => $row['memberID'],
                                            'name' => $row['name'],
                                            'dob' => $row['dob']);
            }




//get the result size
$count = sizeof($result_2d_arr);

//order the array
if($order != "asc") {
    $result_2d_arr = array_reverse($result_2d_arr);
}

//get the subview of the array
$result_2d_arr = array_slice($result_2d_arr, $offset, $limit);



echo "{";
echo '"total": ' . $count . ',';
echo '"rows": ';
echo json_encode($result_2d_arr);
echo "}";

}

?>

The JSON response is as follows...

{"total": 23,"rows": [{"memberID":"1","name":"asd","dob":"2015-06-03"},{"memberID":"2","name":"asd","dob":"2015-06-03"},{"memberID":"3","name":"asd","dob":"2015-06-03"},{"memberID":"4","name":"asd","dob":"2015-06-03"},{"memberID":"5","name":"asd","dob":"2015-06-03"},{"memberID":"6","name":"asd","dob":"2015-06-03"},{"memberID":"7","name":"asd","dob":"2015-06-03"},{"memberID":"8","name":"asd","dob":"2015-06-03"},{"memberID":"9","name":"asd","dob":"2015-06-03"},{"memberID":"10","name":"asd","dob":"2015-06-03"}]}

Finally...got it working. I put this code in the else part.

else {
$count=0;
echo "{";
echo '"total": ' . $count . ',';
echo '"rows": ';
echo json_encode(array());
echo "}";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM