Ver Mensaje Individual
  #54 (permalink)  
Antiguo 20/12/2012, 09:57
Avatar de DeivisAndres
DeivisAndres
 
Fecha de Ingreso: febrero-2012
Ubicación: Colombia
Mensajes: 305
Antigüedad: 12 años, 2 meses
Puntos: 41
Respuesta: llenar arreglo con checkbox y caja de texto

Bueno aqui te tengo otra solucion pruebalo y me cuentas como te fue:

Código PHP:
Ver original
  1. <?php
  2.        
  3.     /** conexion ***************************/
  4.      $link = mysql_connect('localhost', 'root', ''); // conectamos a la base de datos
  5.      if(!$link) { // si no se conecta que mande error
  6.         die("Error al intentar conectar: ".mysql_error());
  7.      }
  8.      $db_link = mysql_select_db('prueba', $link); // seleccionamos la base de datos
  9.      if(!$db_link) { // si no selecciona la BD que mande error
  10.         die("Error al intentar seleccionar la base de datos". mysql_error());
  11.      }
  12.      /** fin conexion ************************/
  13.    
  14.     $showsql = mysql_query("SELECT * FROM tema", $link) or die(mysql_error());
  15.            
  16.     if(isset($_REQUEST["ingresar"]) && $_REQUEST["ingresar"] == "Ingresar"){   
  17.         if((!empty($_REQUEST['norm'])) && (!empty($_POST['year']))){
  18.             $textos = $_REQUEST['norm'];
  19.             $year = $_REQUEST['year'];
  20.         }          
  21.        
  22.         print_r($textos);
  23.         print_r('<br />');     
  24.        
  25.         for ($i=0;$i<count($year);$i++){
  26.             if(empty($year[$i])){                          
  27.                 unset($year[$i]);
  28.             }
  29.         }
  30.        
  31.         $year = array_values($year);
  32.        
  33.         print_r($year);
  34.        
  35.         for ($i=0;$i<count($textos);$i++){                 
  36.             $cedula = "000".$i;                                    
  37.             if((isset($_REQUEST['year'])) && (isset($_REQUEST['norm'])))                    
  38.             {              
  39.                 $insertSQL = mysql_query("INSERT INTO coco (identificacion, id_progsocial, ano) VALUES ('$cedula','".$textos[$i]."','".$year[$i]."')", $link) or die(mysql_error());                           
  40.             }
  41.         }      
  42.     }
  43. ?>
  44. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml2/DTD/xhtml1-strict.dtd">
  45. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  46. <head>
  47. </head>
  48. <body>
  49. <form action="" method="post" name="form1" id="form1">
  50.     <?php      
  51.         while($Mostrar = mysql_fetch_array($showsql)){ 
  52.     ?>
  53.         <input name="norm[]" type="checkbox" value="<?php echo $Mostrar['Valor']; ?>"><?php echo $Mostrar['Nombre']; ?>
  54.         <input name="year[]" type="text" value="" /><br />     
  55.     <?php      
  56.         }
  57.     ?> 
  58.     <input id="input" type="submit" name="ingresar" value="Ingresar" />
  59. </form>
  60. </body>
  61. </html>

NOTA: lo que hago es eliminar la posición del arreglo que este vacía y después lo que hago es reorganizar el arreglo.

Código PHP:
Ver original
  1. for ($i=0;$i<count($year);$i++){
  2.        if(empty($year[$i])){                           
  3.     unset($year[$i]);
  4.        }
  5. }      
  6. $year = array_values($year);