Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/10/2012, 11:09
Avatar de jlct
jlct
 
Fecha de Ingreso: abril-2012
Ubicación: Venezuela
Mensajes: 148
Antigüedad: 12 años, 1 mes
Puntos: 19
Registro de transacciones

Buenas tardes foreros, necesito de ayuda y me orienten sobre lo que tengo que hacer.

resulta que necesito incluir detalle en mis formularios pero no tengo idea de como hacerlo.. la idea es que el usuario pueda incluir tantos registros como quiera.. y esos pueden ser 1, 2, 3 o hasta mas campos por fila (segun la magnitud del detalle) hasta ahora solo les puedo facilitar como llevo el registro de los formularios normales.

medicina.php
Código PHP:
Ver original
  1. <?
  2. include("../../modelos/config.php");
  3. $c = new Conexion;
  4. $c->Conectar();
  5.  
  6. $registros = 10;
  7.  
  8. if (!$pagina) {
  9.     $inicio = 0;
  10.     $pagina = 1;
  11. }
  12. else {
  13.     $inicio = ($pagina - 1) * $registros;
  14. }
  15. $valor = $_GET['valor'];
  16. $msg = $_REQUEST['alerta'];
  17.  
  18. ?>
  19. <!doctype html>
  20. <html lang="es">
  21. <head>
  22.     <meta http-equiv="Content-Type" content="text/html" charset="utf-8" />
  23.     <title>Unidad de Producción</title>
  24.     <link rel="shortcut icon" href="../../imagenes/icono.png">
  25.     <link rel="stylesheet" href="../../css/estilo.css" />
  26.     <script src="medicina_ajax.js" language="javascript" type="text/javascript"></script>
  27. </head>
  28. <body class="no-js">
  29.     <? include("../../nav/nav_menuprincipal.html"); ?>
  30.     <article>
  31.     <header>
  32.         <br />
  33.         <h1 align="center">Medicinas</h1>
  34.     </header><br /><br />
  35.     <section><p><form name="form1" id="form1" method="post">
  36.     <fieldset>
  37.     <ol>
  38.     <center class="caja">
  39.     <input type="text" size="30" id="texto" onKeyUp="Buscar()" value="<?=$valor?>"/>
  40.     <input type="button" name="insert" id="insert" value="Nuevo" onClick="location.href = 'medicina_nuevo.php' "/>
  41.     </center>
  42.     <?
  43.     if (empty($valor))
  44.     {
  45.     if (!empty($msg))
  46.     {
  47.         echo "<script language='javascript'>alert('$msg');</script>";
  48.     }
  49.     $query = mysql_query("SELECT id_medicina FROM tmedicina");
  50.     $total_registros = mysql_num_rows($query);
  51.     $resultados = mysql_query("SELECT m.id_medicina ID, m.nombre medicina, CASE m.tipo WHEN  'G' THEN  'Medicina General' WHEN  'D' THEN  'Desparacitantes' ELSE  'Vacunas' END tipo, m.existencia, a.nombre almacen FROM tmedicina m INNER JOIN talmacen a ON m.almacen = a.id_almacen ORDER BY m.nombre ASC LIMIT $inicio, $registros");
  52.     }
  53.     else {
  54.     $query = mysql_query("SELECT id_medicina FROM tmedicina where nombre LIKE '%$valor%'");
  55.     $total_registros = mysql_num_rows($query);
  56.     $resultados = mysql_query("SELECT m.id_medicina ID, m.nombre medicina, CASE m.tipo WHEN  'G' THEN  'Medicina General' WHEN  'D' THEN  'Desparacitantes' ELSE  'Vacunas' END tipo, m.existencia, a.nombre almacen FROM tmedicina m INNER JOIN talmacen a ON m.almacen = a.id_almacen WHERE m.nombre LIKE '%$valor%' ORDER BY m.nombre ASC LIMIT $inicio, $registros");
  57.     }  
  58.     $total_paginas = ceil($total_registros / $registros);                  
  59.  
  60.     if($total_registros) {
  61.         echo '<center id="resultados">';
  62.         echo '<table width="400" border="1" cellspacing="0" cellpadding="0">';
  63.         echo '<tr>';
  64.             echo '<td>Medicina</td>';
  65.             echo '<td>Tipo</td>';
  66.             echo '<td>Existencia</td>';
  67.             echo '<td>Almacen</td>';
  68.         echo '<td>Acciones</td>';
  69.         echo '</tr>';
  70.    
  71.         while($row=@mysql_fetch_array($resultados)) {
  72.            
  73.             echo '<tr>';
  74.             echo '<td>'.$row['medicina'].'</td>';
  75.             echo '<td>'.$row['tipo'].'</td>';
  76.             echo '<td>'.$row['existencia'].'</td>';
  77.             echo '<td>'.$row['almacen'].'</td>';
  78.             echo '<td><span style="cursor: pointer;" onclick="location.href = \'medicina_editar.php?ID='.$row['ID'].'\'">Editar</span><br><span style="cursor: pointer;" onclick="Confirmar('.$row['ID'].')">Eliminar</span></td>';
  79.             echo '</tr>';
  80.            
  81.         }
  82.             echo '</table>';
  83.        
  84.     } else {
  85.         echo "<script>alert('sin resultados');</script>";
  86.     }
  87.    
  88.     @mysql_free_result($resultados);               
  89.    
  90.     if($total_registros) {
  91.        
  92.         if(($pagina - 1) > 0) {
  93.             echo "<a href='medicina.php?pagina=".($pagina-1)."&valor=$valor'>< Anterior</a> ";
  94.         }
  95.        
  96.         for ($i=1; $i<=$total_paginas; $i++){
  97.             if ($pagina == $i) {
  98.                 echo "<b>".$pagina."</b> ";
  99.             } else {
  100.                 echo "<a href='medicina.php?pagina=$i&valor=$valor'>$i</a> ";
  101.             }  
  102.         }
  103.      
  104.         if(($pagina + 1)<=$total_paginas) {
  105.             echo " <a href='medicina.php?pagina=".($pagina+1)."&valor=$valor'>Siguiente ></a>";
  106.         }
  107.        
  108.         echo "</center>";
  109.        
  110.     }
  111.     ?>
  112.     </ol>
  113.     </fieldset>
  114.     </p></form><br /><br /></section>
  115.     </article>
  116.     <footer>
  117.         <p>&copy; 2012 Universidad Politécnica Territorial de Portuguesa. Todos los derechos reservados.</p>
  118.     </footer>
  119. </body>
  120. </html>
  121. <? @mysql_close($c);?>

medicina_ajax.js
Código Javascript:
Ver original
  1. &#65279;function Buscador(){
  2. var xmlhttp = false;
  3. try {
  4.     xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  5. } catch (e) {
  6.     try {
  7.         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  8.     } catch (E) {
  9.         xmlhttp = false;
  10.     }
  11. }
  12. if (!xmlhttp && typeof XMLHttpRequest!='undefined')
  13. {
  14.     xmlhttp = new XMLHttpRequest();
  15. }
  16. return xmlhttp;
  17. }
  18.  
  19. function Buscar()
  20. {
  21.     var Texto = document.getElementById('texto').value;
  22.     var Resultado = document.getElementById('resultados');
  23.     ajax = Buscador();
  24.     ajax.open("GET","medicina_buscador.php?q="+Texto);
  25.     ajax.onreadystatechange = function() {
  26.         if (ajax.readyState == 4) {
  27.             Resultado.innerHTML = ajax.responseText;
  28.         }
  29.     }
  30.     ajax.send(null);
  31. }
  32.  
  33. function Eliminar(Texto)
  34. {
  35.     var Resultado = document.getElementById('resultados');
  36.     ajax = Buscador();
  37.     ajax.open("GET","medicina_eliminar.php?q="+Texto);
  38.     ajax.onreadystatechange = function() {
  39.         if (ajax.readyState == 4) {
  40.             Resultado.innerHTML = ajax.responseText;
  41.         }
  42.     }
  43.     ajax.send(null);
  44. }
  45.  
  46. function Confirmar(Texto)
  47. {
  48.     c = confirm("¿Desea eliminar el registro?");
  49.     if (c)
  50.     {
  51.         Eliminar(Texto);
  52.     }
  53.     else return false;
  54. }

medicina_buscador.php
Código PHP:
Ver original
  1. <?php
  2. include("../../modelos/config.php");
  3. $c = new Conexion;
  4. $c->Conectar();
  5. $valor = $_GET['q'];
  6. $registros = 10;
  7.  
  8. if (!$pagina) {
  9.     $inicio = 0;
  10.     $pagina = 1;
  11. }
  12. else {
  13.     $inicio = ($pagina - 1) * $registros;
  14. }
  15.     $query = mysql_query("SELECT id_medicina FROM tmedicina where nombre LIKE '%$valor%'");
  16.     $total_registros = mysql_num_rows($query);
  17.     $resultados = mysql_query("SELECT m.id_medicina ID, m.nombre medicina, CASE m.tipo WHEN  'G' THEN  'Medicina General' WHEN  'D' THEN  'Desparacitantes' ELSE  'Vacunas' END tipo, m.existencia, a.nombre almacen FROM tmedicina m INNER JOIN talmacen a ON m.almacen = a.id_almacen WHERE m.nombre LIKE '%$valor%' ORDER BY m.nombre ASC LIMIT $inicio, $registros");
  18.     $total_paginas = ceil($total_registros / $registros);                  
  19.  
  20.     if($total_registros) {
  21.         echo '<center id="resultados">';
  22.         echo '<table width="400" border="1" cellspacing="0" cellpadding="0">';
  23.         echo '<tr>';
  24.             echo '<td>Medicina</td>';
  25.             echo '<td>Tipo</td>';
  26.             echo '<td>Existencia</td>';
  27.             echo '<td>Almacen</td>';
  28.         echo '<td>Acciones</td>';
  29.         echo '</tr>';
  30.    
  31.         while($row= @mysql_fetch_array($resultados)) {
  32.            
  33.             echo '<tr>';
  34.             echo '<td>'.$row['medicina'].'</td>';
  35.             echo '<td>'.$row['tipo'].'</td>';
  36.             echo '<td>'.$row['existencia'].'</td>';
  37.             echo '<td>'.$row['almacen'].'</td>';
  38.             echo '<td><a href="pagina.php?id='.$row['ID'].'"><span style="cursor: pointer;">Editar</span></a><br><span style="cursor: pointer;" onclick="Confirmar('.$row['ID'].')">Eliminar</span></td>';
  39.             echo '</tr>';
  40.            
  41.         }
  42.             echo '</table>';
  43.        
  44.     } else {
  45.         echo "<script>alert('sin resultados');</script>";
  46.     }
  47.    
  48.     @mysql_free_result($resultados);               
  49.    
  50.     if($total_registros) {
  51.        
  52.         if(($pagina - 1) > 0) {
  53.             echo "<a href='medicina.php?pagina=".($pagina-1)."&valor=$valor'>< Anterior</a> ";
  54.         }
  55.        
  56.         for ($i=1; $i<=$total_paginas; $i++){
  57.             if ($pagina == $i) {
  58.                 echo "<b>".$pagina."</b> ";
  59.             } else {
  60.                 echo "<a href='medicina.php?pagina=$i&valor=$valor'>$i</a> ";
  61.             }  
  62.         }
  63.      
  64.         if(($pagina + 1)<=$total_paginas) {
  65.             echo " <a href='medicina.php?pagina=".($pagina+1)."&valor=$valor'>Siguiente ></a>";
  66.         }
  67.        
  68.         echo "</center>";
  69.        
  70.     }
  71. ?>

medicina_eliminar.php
Código PHP:
Ver original
  1. <?php
  2. include("../../modelos/config.php");
  3. $c = new Conexion;
  4. $c->Conectar();
  5. $q = $_GET['q'];
  6. $sql = "Delete from tmedicina where id_medicina=$q";
  7. $c = mysql_query($sql);
  8. if ($c)
  9. {
  10.     print "<font color='black'><b>Registro eliminado correctamente </b></font><br /><a href='medicina.php'>Atras</a></b>";
  11. }
  12. else {
  13.     print "<font color='black'><b>No se elimino el registro porque hay registros asociados a la medicina</b></font><br /><a href='medicina.php'>Atras</a>";
  14. }
  15. ?>