Ver Mensaje Individual
  #7 (permalink)  
Antiguo 03/07/2013, 08:43
Avatar de adryan310
adryan310
 
Fecha de Ingreso: septiembre-2012
Mensajes: 450
Antigüedad: 11 años, 8 meses
Puntos: 3
Pregunta Respuesta: ¿Como hacer tablas dinamicas usando PHP, JQuery y Json o Ajax?

OK! mira la cuestión es que tengo este código en php que me retorna al llamar un procedimiento almacenado todos los depósitos hechos por un usuario 'x'
Código PHP:
        require_once('CConexion.php');
    
    
$strDepositante $_GET['Depositante'];
    
$m_Depositos = array();
    
        
// armamos la query
        
$resultado $link_id->query("CALL details_depositos_depositante('".$strDepositante."')");     
  
        while (
$filas=$resultado->fetch_assoc()) 
    {
       
$m_Depositos[]= $filas;
    }
            
      print 
json_encode($m_Depositos); 
luego capturo ese array que envio al json de esta manera
Código:
$(document).ready(function(){
  $(':submit').live('click', function() { // This event fires when a button is clicked
      var button = $(this).val();
      $.ajax({ // ajax call starts
          url: 'conexion/CBuscarDepoCliente.php', // JQuery loads serverside.php
          data: 'Depositante=' + $(this).val(), // Send value of the clicked button
          dataType: 'json', // Choosing a JSON datatype
          success: function(data) // Variable data contains the data we get from serverside
          {
              //$('#wines').html(''); // Clear #wines div
              
              if (button == 'Buscar...') { // If clicked buttons value is all, we post every wine
                  for (var i in data.m_Depositos) {
					  $('#tableDeposits').append('<tr>');
					  $('#tableDeposits').append('<td>');
                      $('#tableDeposits').append(data.red[i]);
					  $('#tableDeposits').append('</td>');
					  $('#tableDeposits').append('</tr>');
                  }   
              }           
          }
      });
      return false; // keeps the page from not refreshing 
  });
});
Y esto lo tengo en la pagina donde debe de cargarme los depositos
Código HTML:
<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
       <script src="js/tablaBuscaDepositos.js"></script>
   </head>
   <body>
        <form id="frm_Ins" name="frm_Ins" action="" method="post">
        <fieldset>
            <input id="txtDepo" name="txtDepo" type="text" placeholder="603940994" value="">
             
            <input id="cmdEnter" name="cmdEnter" type="submit" class="btn btn-primary" value="Buscar..." onClick="">

            <div id="wines">
              <!-- Tabla donde se muestran los depositos via ajax-->
              <table id="tableDeposits" class="table table-bordered">
                 <tr>
                  <td><strong># Deposito</strong></td>
                  <td><strong>Depositante</strong></td>
                  <td><strong>Usuario</strong></td>
                  <td><strong>Fecha</strong></td>
                  <td><strong>Monto</strong></td>
                  <td><strong>Tipo</strong></td>
                 </tr>
              </table>
              </div>
        </fieldset>
   </body>
</html> 
Ahora si alguna ayuda por favor ?