elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: ¿Eres nuevo? ¿Tienes dudas acerca del funcionamiento de la comunidad? Lee las Reglas Generales


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web
| | |-+  PHP (Moderador: #!drvy)
| | | |-+  filtrar datos de un jtable en php
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: filtrar datos de un jtable en php  (Leído 2,799 veces)
rafaechev

Desconectado Desconectado

Mensajes: 2


Ver Perfil
filtrar datos de un jtable en php
« en: 16 Marzo 2015, 02:10 am »

Hola foreros espero que se encuentren bien, tengo una duda y espero que ustedes me puedan ayudar. estoy creando un sistema web para un colegio en el que trabajo y resulta que estoy ocupando jtable. todo resulta bien el problema es que no puedo filtrar los datos de una tabla ya que solo existe esto para el lenguaje java y asp.net , como podria hacerlo para crear el filtro en php.

tengo un archivo php llamado funcionarios.php que contiene lo siguiente

Código
  1. <html>
  2.  <head>
  3.  
  4.    <link href="../themes/redmond/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" />
  5. <link href="../scripts/jtable/themes/metro/blue/jtable.css" rel="stylesheet" type="text/css" />
  6.  
  7. <script src="../scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
  8.    <script src="../scripts/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script>
  9.    <script src="../scripts/jtable/jquery.jtable.js" type="text/javascript"></script>
  10.  
  11.    <!-- Import CSS file for validation engine (in Head section of HTML) -->
  12. <link href="../css/validationEngine.jquery.css" rel="stylesheet" type="text/css" />
  13.  
  14. <!-- Import javascript files for validation engine (in Head section of HTML) -->
  15. <script type="text/javascript" src="../js/jquery.validationEngine.js"></script>
  16. <script type="text/javascript" src="../js/jquery.validationEngine-es.js"></script>
  17.  
  18. </head>
  19.  
  20.  <body>
  21. <div id="PeopleTableContainer" style="width:auto;"></div>
  22.  
  23. <script type="text/javascript">
  24.  
  25. $(document).ready(function () {
  26.  
  27.  
  28.  
  29.    //Prepare jTable
  30. $('#PeopleTableContainer').jtable({
  31. title: 'Tabla de Funcionarios',
  32. paging: true,
  33. pageSize: 14,
  34. sorting: true,
  35. defaultSorting: 'nombres ASC',
  36. actions: {
  37. listAction: 'accionFuncionarios.php?action=list',
  38. createAction: 'accionFuncionarios.php?action=create',
  39. updateAction: 'accionFuncionarios.php?action=update',
  40. deleteAction: 'accionFuncionarios.php?action=delete'
  41. },
  42. fields: {
  43. rut: {
  44. title: 'Rut',
  45. key: true,
  46. edit: true,
  47. list: true,
  48. width: '15%',
  49. inputClass: 'validate[required]'
  50. },
  51. nombres: {
  52. title: 'Nombres',
  53. width: '15%',
  54. inputClass: 'validate[required]'
  55. },
  56. apellidos: {
  57. title: 'Apellidos',
  58. width: '15%',
  59. inputClass: 'validate[required]'
  60. },
  61. correo: {
  62. title: 'Correo',
  63. width: '17%',
  64. inputClass: 'validate[custom[email]]'
  65. },
  66. telefono : {
  67. title: 'Teléfono',
  68. width: '15%',
  69. inputClass: 'validate[required,custom[phone]]'
  70. },
  71. estado: {
  72.                     title: 'Estado',
  73.                     width: '10%',
  74.                     type: 'checkbox',
  75. setOnTextClick: false,
  76.                     values: { 'false': 'Inactivo', 'true': 'Vigente' },
  77.                     defaultValue: 'true'
  78.  
  79. }
  80. },
  81.            //Initialize validation logic when a form is created
  82.            formCreated: function (event, data) {
  83.                data.form.validationEngine();
  84.            },
  85.            //Validate form when it is being submitted
  86.            formSubmitting: function (event, data) {
  87.                return data.form.validationEngine('validate');
  88.            }
  89. });
  90.  
  91. //Load person list from server
  92. $('#PeopleTableContainer').jtable('load');
  93. //jQuery("#jtable-create-form").validationEngine();
  94. });
  95.  
  96. </script>
  97.  
  98.  </body>
  99. </html>
  100.  
  101.  
  102. y el codigo php que lo recibe y que inteactua con la base de datos lo llame accionFuncionarios.php y contiene lo siguiente.
  103.  
  104. <?php
  105.  
  106. try
  107. {
  108. //Open database connection
  109. $con = mysql_connect("localhost","root","");
  110. mysql_select_db("laboratorios", $con);
  111. mysql_query ("SET NAMES 'utf8'");
  112.  
  113. //Getting records (listAction)
  114. if($_GET["action"] == "list")
  115. {
  116. //Get record count
  117. $result = mysql_query("SELECT COUNT(*) AS RecordCount FROM funcionario;");
  118. $row = mysql_fetch_array($result);
  119. $recordCount = $row['RecordCount'];
  120.  
  121. //Get records from database
  122. $result = mysql_query("SELECT * FROM funcionario ORDER BY " . $_GET["jtSorting"] . " LIMIT " . $_GET["jtStartIndex"] . "," . $_GET["jtPageSize"] . ";");
  123.  
  124. //Add all records to an array
  125. $rows = array();
  126. while($row = mysql_fetch_array($result))
  127. {
  128.    $rows[] = $row;
  129. }
  130.  
  131. //Return result to jTable
  132. $jTableResult = array();
  133. $jTableResult['Result'] = "OK";
  134. $jTableResult['TotalRecordCount'] = $recordCount;
  135. $jTableResult['Records'] = $rows;
  136. print json_encode($jTableResult);
  137. }
  138. //Creating a new record (createAction)
  139. else if($_GET["action"] == "create")
  140. {
  141. //Insert record into database
  142. $result = mysql_query("INSERT INTO funcionario(rut, nombres, apellidos, correo, telefono, estado) VALUES('" . $_POST["rut"] . "', '".$_POST["nombres"]. "', '".$_POST["apellidos"]. "', '".$_POST["correo"]. "', '".$_POST["telefono"]. "' , '".$_POST["estado"]."');");
  143.  
  144. //Get last inserted record (to return to jTable)
  145. $result = mysql_query("SELECT * FROM funcionario WHERE rut = '".$_POST["rut"]."';");
  146. $row = mysql_fetch_array($result);
  147.  
  148. //Return result to jTable
  149. $jTableResult = array();
  150. $jTableResult['Result'] = "OK";
  151. $jTableResult['Record'] = $row;
  152. print json_encode($jTableResult);
  153. }
  154. //Updating a record (updateAction)
  155. else if($_GET["action"] == "update")
  156. {
  157. //Update record in database
  158. $result = mysql_query("UPDATE funcionario SET rut = '" . $_POST["rut"] . "', nombres = '" . $_POST["nombres"] . "', apellidos = '" . $_POST["apellidos"] . "', correo = '" . $_POST["correo"] . "', telefono = '" . $_POST["telefono"] . "', estado = '" . $_POST["estado"] . "' WHERE rut = '" . $_POST["rut"] . "';");
  159.  
  160. //Return result to jTable
  161. $jTableResult = array();
  162. $jTableResult['Result'] = "OK";
  163. print json_encode($jTableResult);
  164. }
  165. //Deleting a record (deleteAction)
  166. else if($_GET["action"] == "delete")
  167. {
  168. //Delete from database
  169. $result = mysql_query("DELETE FROM funcionario WHERE rut = '" . $_POST["rut"] . "';");
  170.  
  171. //Return result to jTable
  172. $jTableResult = array();
  173. $jTableResult['Result'] = "OK";
  174. print json_encode($jTableResult);
  175. }
  176.  
  177. //Close database connection
  178. mysql_close($con);
  179.  
  180. }
  181. catch(Exception $ex)
  182. {
  183.    //Return error message
  184. $jTableResult = array();
  185. $jTableResult['Result'] = "ERROR";
  186. $jTableResult['Message'] = $ex->getMessage();
  187. print json_encode($jTableResult);
  188. }
  189.  
  190. ?>
  191.  
esperando haber entregado la información necesaria para poder obtener ayuda de antemano les agradezco, estaré atento a sus comentarios.

Mod: Obligatorio el uso de etiquetas GeSHi.


« Última modificación: 16 Marzo 2015, 04:23 am por #!drvy » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines