Advertisement
Guest User

Untitled

a guest
Jun 19th, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Simple Example Bootgrid (Server Side) with PHP, MySQL and Ajax</title>
  6. <link rel="stylesheet" href="dist/bootstrap.min.css" type="text/css" media="all">
  7. <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
  8. <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
  9. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  10. <script src="dist/jquery.bootgrid.min.js"></script>
  11. </head>
  12. <body>
  13. <div class="container">
  14. <div class="">
  15. <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>
  16. <div class="">
  17.  
  18. <table id="employee_grid" style="margin-top:10px" class="table table-bordered table-condensed table-hover table-striped" width="100%" cellspacing="0">
  19. <thead>
  20. <tr>
  21. <th data-column-id="id_cliente" data-type="numeric">ID</th>
  22. <th data-column-id="nombre">Nombre</th>
  23. <th data-column-id="tipo_doc">Tipo Documento</th>
  24. <th data-column-id="telfmovil">Telf/Movil</th>
  25. <th ddata>Accion</th>
  26. </tr>
  27. </thead>
  28.  
  29.  
  30. </table>
  31. </div>
  32. </div>
  33.  
  34. </div>
  35.  
  36. <script type="text/javascript">
  37. $( document ).ready(function() {
  38. $("#employee_grid").bootgrid({
  39. ajax: true,
  40. post: function ()
  41. {
  42. /* To accumulate custom parameter with the request object */
  43. return {
  44. id: "b0df282a-0d67-40e5-8558-c9e93b7befed"
  45. };
  46. },
  47. url: "response.php",
  48. formatters: {
  49.  
  50. }
  51. });
  52. });
  53. </script>
  54. </body>
  55. </html>
  56.  
  57. <?php
  58. //include connection file
  59. include_once("connection.php");
  60.  
  61. // initilize all variable
  62. $params = $totalRecords = $data = array();
  63.  
  64. $sqlTot = $sqlRec = $where = "";
  65.  
  66.  
  67. $params = $_REQUEST;
  68. $limit = $params["rowCount"];
  69.  
  70. if (isset($params["current"])) { $page = $params["current"]; } else { $page=1; };
  71. $start_from = ($page-1) * $limit;
  72. // check search value exist
  73. if( !empty($params['searchPhrase']) ) {
  74. $where .=" WHERE ";
  75. $where .=" ( id_cliente LIKE '".$params['searchPhrase']."%' ";
  76. $where .=" OR nombre LIKE '".$params['searchPhrase']."%' ";
  77.  
  78. $where .=" OR telfmovil LIKE '".$params['searchPhrase']."%' )";
  79. }
  80.  
  81. // getting total number records without any search
  82. $sql = "SELECT * FROM `cliente` ";
  83. $sqlTot .= $sql;
  84. $sqlRec .= $sql;
  85.  
  86.  
  87. //concatenate search sql if value exist
  88. if(isset($where) && $where != '') {
  89.  
  90. $sqlTot .= $where;
  91. $sqlRec .= $where;
  92. }
  93. if ($limit!=-1)
  94. $sqlRec .= "LIMIT $start_from, $limit";
  95.  
  96. $queryTot = mysqli_query($conn, $sqlTot) or die("database error:". mysqli_error($conn));
  97.  
  98.  
  99. $totalRecords = mysqli_num_rows($queryTot);
  100.  
  101. $queryRecords = mysqli_query($conn, $sqlRec) or die("error to fetch employees data");
  102.  
  103. //iterate on results row and create new index array of data
  104. while( $row = mysqli_fetch_assoc($queryRecords) ) {
  105. $data[] = $row;
  106. //echo "<pre>";print_R($data);die;
  107. }
  108.  
  109. $json_data = array(
  110. "current" => intval( $params['current'] ),
  111. "rowCount" => 10,
  112. "total" => intval( $totalRecords ),
  113. "rows" => $data // total data array
  114. );
  115.  
  116. echo json_encode($json_data); // send data as json format
  117. ?>
  118.  
  119. <?php
  120. /* Database connection start */
  121. $servername = "localhost";
  122. $username = "root";
  123. $password = "123";
  124. $dbname = "dbagricola";
  125.  
  126. $conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());
  127.  
  128. /* check connection */
  129. if (mysqli_connect_errno()) {
  130. printf("Connect failed: %sn", mysqli_connect_error());
  131. exit();
  132. }
  133.  
  134. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement