Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] condicionar valor de variable para filtro de consulta

Estas en el tema de condicionar valor de variable para filtro de consulta en el foro de PHP en Foros del Web. hola buenos dias a todos antes que nada gracias por tomarse la molestia de leer mi post veran soy nuevo con lo referente a todo ...
  #1 (permalink)  
Antiguo 14/04/2015, 09:59
 
Fecha de Ingreso: abril-2015
Mensajes: 13
Antigüedad: 9 años
Puntos: 0
condicionar valor de variable para filtro de consulta

hola buenos dias a todos antes que nada gracias por tomarse la molestia de leer mi post veran soy nuevo con lo referente a todo lo de programacion web, estoy aprendiendo de forma autodidacta, tengo un mal funcionamiento el cual no he logrado solucionar debido a mi bajo nivel de conocimiento de la materia, espero que alguien me pueda orientar con sus opiniones o sugerencias se los agradecere enomemente gracias

mi problema es el siguiente al iniciar mi archivo index.php me carga mis registros sin ningun problema

Código HTML:
Ver original
  1. <!DOCTYPE html>
  2.     <meta charset="UTF-8">
  3.     <title>Crud</title>
  4.     <link rel="stylesheet" type="text/css" href="lib/themes/bootstrap/easyui.css">
  5.     <link rel="stylesheet" type="text/css" href="lib/themes/icon.css">
  6.     <link rel="stylesheet" type="text/css" href="lib/themes/color.css">
  7.     <link rel="stylesheet" type="text/css" href="lib/demo.css">
  8.     <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.min.js"></script>
  9.     <script type="text/javascript" src="lib/jquery.easyui.min.js"></script>
  10. </head>
  11. <!-- botones -->
  12.    
  13.     <p>Menu.</p>
  14.     <div style="margin:10px 0 40px 0;"></div>
  15.     <p>Basic Buttons</p>
  16.     <div style="padding:5px 0;">
  17.         <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'">Add</a>
  18.         <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">Remove</a>
  19.         <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'">Save</a>
  20.         <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="filtroFech()">Filtro</a>
  21.         <a href="http://qcomercio.com/" class="easyui-linkbutton">Text Button</a>
  22.         <a href="fil.html" class="easyui-linkbutton c1" style="width:120px">Button1</a>
  23.     </div>
  24. <!-- final -->
  25.     <h2>CRUD</h2>
  26.    
  27.    
  28.     <table id="dg" title="Agenda" class="easyui-datagrid" style="width:800px;height:380px"
  29.     url="get_users.php"
  30.     toolbar="#toolbar" pagination="true"
  31.     rownumbers="true" fitColumns="true" singleSelect="true">
  32.     <thead>
  33.         <tr>
  34.             <th field="nombre" width="70">nombre</th>
  35.             <th field="lugar" width="70">lugar</th>
  36.             <th field="concepto" width="70">Concepto</th>
  37.             <th field="ident" width="70">ident</th>
  38.             <th field="servicio" width="70">servicio</th>
  39.             <th field="fecha" width="50">fecha</th>
  40.         </tr>
  41.     </thead>
  42. <div id="toolbar">
  43.     <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">Nuevo</a>
  44.     <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">Editar</a>
  45.     <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">Eliminar</a>
  46. </div>
  47.  
  48. <div id="dlg" class="easyui-dialog" style="width:400px;height:380px;padding:10px 20px"
  49. closed="true" buttons="#dlg-buttons">
  50. <div class="ftitle">User Information</div>
  51. <form id="fm" method="post" novalidate>
  52.     <div class="fitem">
  53.         <label>Nombre:</label>
  54.         <input name="nombre" class="easyui-textbox" required="true">
  55.     </div>
  56.     <div class="fitem">
  57.         <label>Lugar:</label>
  58.         <input name="lugar" class="easyui-textbox" required="true">
  59.     </div>
  60.     <div class="fitem">
  61.         <label>Concepto:</label>
  62.         <input name="concepto" class="easyui-textbox" data-options="multiline:true" style="height:60px">
  63.     </div>
  64.     <div class="fitem">
  65.         <label>Email:</label>
  66.         <input name="ident" class="easyui-textbox" validType="date">
  67.     </div>
  68.     <div class="fitem">
  69.     <label>Servicio:</label>
  70.     <input  name="servicio" class="easyui-combobox" data-options="
  71.     valueField: 'label',
  72.     textField: 'value',
  73.     data: [{
  74.     label: 'compra',
  75.     value: 'compra'
  76.     },{
  77.     label: 'venta',
  78.     value: 'venta'
  79.     },{
  80.     label: 'renta',
  81.     value: 'renta'
  82.     }]" />
  83.      </div>
  84.      <div class="fitem">
  85.         <label>FECHA:</label>
  86.         <input name="fecha" class="easyui-datebox" data-options="prompt:'formato (mm/dd/YYYY)'">
  87.     </div>
  88.   </form>
  89. </div>
  90. <div id="dlg-buttons">
  91.     <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveUser()" style="width:90px">Save</a>
  92.     <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancel</a>
  93. </div>
  94. <!-- form 2 -->
  95. <div id="dlgdos" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
  96. closed="true" buttons="#dlg-buttonsdos">
  97. <div class="ftitle">Filtro</div>
  98. <form id="fmdos" method="post" novalidate>
  99.     <div class="fitem">
  100.         <label>Fecha Inicial</label>
  101.         <input name="fechaini" class="easyui-datebox" data-options="prompt:'formato (mm/dd/YYYY)'" required="true">
  102.     </div>
  103.      <div class="fitem">
  104.         <label>Fecha Final</label>
  105.         <input name="fechafin" class="easyui-datebox" data-options="prompt:'formato (mm/dd/YYYY)'" required="true">
  106.     </div>
  107.   </form>
  108. </div>
  109. <div id="dlg-buttonsdos">
  110.     <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="realizarFil()" style="width:90px">Filtro</a>
  111.     <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlgdos').dialog('close')" style="width:90px">Cancel</a>
  112. </div>
  113. <!-- final form2 -->
  114. <script type="text/javascript">
  115.     var url;
  116.  
  117.     function newUser(){
  118.         $('#dlg').dialog('open').dialog('setTitle','New User');
  119.         $('#fm').form('clear');
  120.         url = 'save_user.php';
  121.     }
  122.     function editUser(){
  123.         var row = $('#dg').datagrid('getSelected');
  124.         if (row){
  125.             $('#dlg').dialog('open').dialog('setTitle','Edit User');
  126.             $('#fm').form('load',row);
  127.             url = 'update_user.php?id='+row.id;
  128.         }
  129.     }
  130.     function saveUser(){
  131.         $('#fm').form('submit',{
  132.             url: url,
  133.             onSubmit: function(){
  134.                 return $(this).form('validate');
  135.             },
  136.             success: function(result){
  137.                 var result = eval('('+result+')');
  138.                 if (result.errorMsg){
  139.                     $.messager.show({
  140.                         title: 'Error',
  141.                         msg: result.errorMsg
  142.                     });
  143.                 } else {
  144.                         $('#dlg').dialog('close');      // close the dialog
  145.                         $('#dg').datagrid('reload');    // reload the user data
  146.                     }
  147.                 }
  148.             });
  149.     }
  150.     function destroyUser(){
  151.         var row = $('#dg').datagrid('getSelected');
  152.         if (row){
  153.             $.messager.confirm('Confirm','Desea Eliminar el Registro?',function(r){
  154.                 if (r){
  155.                     $.post('destroy_user.php',{id:row.id},function(result){
  156.                         if (result.success){
  157.                                 $('#dg').datagrid('reload');    // reload the user data
  158.                             } else {
  159.                                 $.messager.show({   // show error message
  160.                                     title: 'Error',
  161.                                     msg: result.errorMsg
  162.                                 });
  163.                             }
  164.                         },'json');
  165.                 }
  166.             });
  167.         }
  168.     }
  169. // FILTRO
  170. function filtroFech(){
  171.         $('#dlgdos').dialog('open').dialog('setTitle','Filtro');
  172.         $('#fmdos').form('clear');
  173.         url = 'get_users.php';
  174.     }
  175. //
  176. // realizar filtro
  177. function realizarFil(){
  178.         $('#fmdos').form('submit',{
  179.             url: 'get_users.php',
  180.             onSubmit: function(){
  181.                 return $(this).form('validate');
  182.             },
  183.             success: function(result){
  184.                 var result = eval('('+result+')');
  185.                 if (result.errorMsg){
  186.                     $.messager.show({
  187.                         title: 'Error',
  188.                         msg: result.errorMsg
  189.                     });
  190.                 } else {
  191.                         $('#dlgdos').dialog('close');       // close the dialog
  192.                         $('#dg').datagrid('reload');    // reload the user data
  193.                     }
  194.                 }
  195.             });
  196.     }
  197. //
  198.  
  199. <style type="text/css">
  200.     #fm{
  201.         margin:0;
  202.         padding:10px 30px;
  203.     }
  204.     .ftitle{
  205.         font-size:14px;
  206.         font-weight:bold;
  207.         padding:5px 0;
  208.         margin-bottom:10px;
  209.         border-bottom:1px solid #ccc;
  210.     }
  211.     .fitem{
  212.         margin-bottom:5px;
  213.     }
  214.     .fitem label{
  215.         display:inline-block;
  216.         width:80px;
  217.     }
  218.     .fitem input{
  219.         width:160px;
  220.     }
  221. </body>
  222. </html>


me carga mis registros desde este archivo get_users.php

Código PHP:
Ver original
  1. <?php
  2.     date_default_timezone_set('America/Monterrey');
  3.  
  4.    if (isset ($_REQUEST['fechaini']))
  5.     {
  6.     $todayIni = $_REQUEST['fechaini'];
  7.     $todayFin = $_REQUEST['fechafin'];
  8.      
  9.     }
  10.     else
  11.     {
  12.     $todayIni = date("Y-m-d");
  13.     $todayFin = date("Y-m-d");
  14.     }
  15.    
  16.    $todayIni = "2015/04/13";
  17.     $todayFin = "2015/04/13";
  18.     $page = isset($_POST['page']) ? intval($_POST['page']) : 1;
  19.     $rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
  20.     $offset = ($page-1)*$rows;
  21.     $result = array();
  22.  
  23.     include 'conn.php';
  24.    
  25.     $rs = mysql_query("select count(*) from users where fecha BETWEEN '$todayIni' AND '$todayIni'");
  26.     $row = mysql_fetch_row($rs);
  27.     $result["total"] = $row[0];
  28.     $rs = mysql_query("select * from users where fecha BETWEEN '$todayIni' AND '$todayIni' limit $offset,$rows");
  29.    
  30.     $items = array();
  31.     while($row = mysql_fetch_object($rs)){
  32.         array_push($items, $row);
  33.     }
  34.     $result["rows"] = $items;
  35.  
  36.     echo json_encode($result);
  37.  
  38. ?>

al inciar index.html me reliza correctamente me carga los datos con los valores de la variable correspondiente contenidas en mi archivo get.users.php pero al abrir mi formulario modal introducir las nuevas fechas (valores para mi variables) y enviarlos me ejecuta la accion pero no realiza el filtro pareciera que si pasa los valores correctamente a php pero no realiza el filtro correspondiente ya que al momento de enviar los parametros y validar me recarga los datos de mi grid pero no me genera el filtro quisiera saber, si es correcto como estoy recibiendo y condicionando los valores de las variables,
Código PHP:
Ver original
  1. if (isset ($_REQUEST['fechaini']))
  2.     {
  3.     $todayIni = $_REQUEST['fechaini'];
  4.     $todayFin = $_REQUEST['fechafin'];
  5.      
  6.     }
  7.     else
  8.     {
  9.     $todayIni = date("Y-m-d");
  10.     $todayFin = date("Y-m-d");
  11.     }
agradecere mucho su ayuda amigos saludos desde Mexico
  #2 (permalink)  
Antiguo 14/04/2015, 16:40
 
Fecha de Ingreso: abril-2015
Mensajes: 13
Antigüedad: 9 años
Puntos: 0
Respuesta: condicionar valor de variable para filtro de consulta

hola a todos agradezco el que se hayan tomado la molestia de leer mi tema lo he solucionado muchas gracias

Etiquetas: condicionar, fecha, formulario, html, mysql, registro, select, valor, variable
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:37.