Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Simple Example Bootgrid (Server Side) with PHP, MySQL and Ajax</title>
- <link rel="stylesheet" href="dist/bootstrap.min.css" type="text/css" media="all">
- <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
- <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
- <script src="dist/jquery.bootgrid.min.js"></script>
- </head>
- <body>
- <div class="container">
- <div class="">
- <h1><a href="http://phpflow.com/php/simple-example-bootgrid-server-side-with-php-mysql-and-ajax/" target="_blank" rel="nofollow" class="link-red">Filtrando datos de una TABLA</a></h1>
- <div class="">
- <table id="employee_grid" style="margin-top:10px" class="table table-bordered table-condensed table-hover table-striped" width="100%" cellspacing="0">
- <thead>
- <tr>
- <th data-column-id="id_cliente" data-type="numeric">ID</th>
- <th data-column-id="nombre">Nombre</th>
- <th data-column-id="tipo_doc">Tipo Documento</th>
- <th data-column-id="telfmovil">Telf/Movil</th>
- <th ddata>Accion</th>
- </tr>
- </thead>
- </table>
- </div>
- </div>
- </div>
- <script type="text/javascript">
- $( document ).ready(function() {
- $("#employee_grid").bootgrid({
- ajax: true,
- post: function ()
- {
- /* To accumulate custom parameter with the request object */
- return {
- id: "b0df282a-0d67-40e5-8558-c9e93b7befed"
- };
- },
- url: "response.php",
- formatters: {
- }
- });
- });
- </script>
- </body>
- </html>
- <?php
- //include connection file
- include_once("connection.php");
- // initilize all variable
- $params = $totalRecords = $data = array();
- $sqlTot = $sqlRec = $where = "";
- $params = $_REQUEST;
- $limit = $params["rowCount"];
- if (isset($params["current"])) { $page = $params["current"]; } else { $page=1; };
- $start_from = ($page-1) * $limit;
- // check search value exist
- if( !empty($params['searchPhrase']) ) {
- $where .=" WHERE ";
- $where .=" ( id_cliente LIKE '".$params['searchPhrase']."%' ";
- $where .=" OR nombre LIKE '".$params['searchPhrase']."%' ";
- $where .=" OR telfmovil LIKE '".$params['searchPhrase']."%' )";
- }
- // getting total number records without any search
- $sql = "SELECT * FROM `cliente` ";
- $sqlTot .= $sql;
- $sqlRec .= $sql;
- //concatenate search sql if value exist
- if(isset($where) && $where != '') {
- $sqlTot .= $where;
- $sqlRec .= $where;
- }
- if ($limit!=-1)
- $sqlRec .= "LIMIT $start_from, $limit";
- $queryTot = mysqli_query($conn, $sqlTot) or die("database error:". mysqli_error($conn));
- $totalRecords = mysqli_num_rows($queryTot);
- $queryRecords = mysqli_query($conn, $sqlRec) or die("error to fetch employees data");
- //iterate on results row and create new index array of data
- while( $row = mysqli_fetch_assoc($queryRecords) ) {
- $data[] = $row;
- //echo "<pre>";print_R($data);die;
- }
- $json_data = array(
- "current" => intval( $params['current'] ),
- "rowCount" => 10,
- "total" => intval( $totalRecords ),
- "rows" => $data // total data array
- );
- echo json_encode($json_data); // send data as json format
- ?>
- <?php
- /* Database connection start */
- $servername = "localhost";
- $username = "root";
- $password = "123";
- $dbname = "dbagricola";
- $conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());
- /* check connection */
- if (mysqli_connect_errno()) {
- printf("Connect failed: %sn", mysqli_connect_error());
- exit();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement