Ver Mensaje Individual
  #4 (permalink)  
Antiguo 20/04/2010, 08:24
hugarri
 
Fecha de Ingreso: abril-2010
Mensajes: 5
Antigüedad: 14 años, 5 meses
Puntos: 0
Respuesta: Duda con formulario de "multiples" campos

Yo mismo di con la solución después de muchas horas de pruebas, ya hace lo que yo quiero. Lo publico por si a alguien le sirve, y por si alguien ve algún fallo de estilo o puede mejorar mi solución:

Código PHP:
<?    include_once("parametros.php");  ?>

<html>
<head>
<title>resultados</title>
</head>

<?     if (!isset($_POST['jornada']) and !isset($_POST['gol_local'])){    ?>
        <div align="center">
            <form method="post" action= "<? $_SERVER['PHP_SELF']?>">
                Jornada:<br>
                <input type="TEXT" name="jornada"><br>
                <input type="SUBMIT" value="Guardar">
            </form>
        </div>    
    
<?  }elseif(!isset($_POST['gol_local'])){ 
        
// Conexion con la base de datos
        
mysql_connect($db_host,$db_user,$db_pass);
        
// Seleccion de la base de datos
        
mysql_select_db($db_name);
        
// Consulta sql
        
$result1=mysql_query("select nombre from equipos, partidos where (id_jornada=$jornada and id=id_local)");
        
$result2=mysql_query("select nombre from equipos, partidos where (id_jornada=$jornada and id=id_visitante)");
?>
        <form method="post" action= "<? $_SERVER['PHP_SELF']?>">
            <table align="center">
            <?
            
// Impresion de los registros
            
while ($row1=mysql_fetch_array($result1) and $row2=mysql_fetch_array($result2)){
                echo 
'<td>'.$row1["nombre"].'</td>';
                echo 
'<td> <input type="TEXT" size="2" name="gol_local[]"></td>';
                echo 
'<td> <input type="TEXT" size="2" name="gol_visitante[]"></td>';
                echo 
'<td>'.$row2["nombre"].'</td></tr>';
            }
            echo 
'</table>';?>
            <input type="hidden" name="jornada" value="<?php echo $jornada;?>">
        <? echo '<div align="center"><input type="submit" value="Guardar"></div>';
        echo 
'</form>';
        
mysql_free_result($result1);
        
mysql_free_result($result2);

    }else{
        
// Conexion con la base de datos
        
mysql_connect($db_host,$db_user,$db_pass);
        
// Seleccion de la base de datos
        
mysql_select_db($db_name);
        
$gol_local $_POST['gol_local'];
        
$gol_visitante $_POST['gol_visitante'];
        
$jornada $_POST['jornada'];
        
$n count($gol_local);
        
$i 0;
        
$aux=mysql_query("select id_local from partidos where id_jornada=$jornada");
        while (
$i<$n){
            
$x=mysql_fetch_array($aux);
            
$y $x["id_local"];
            
mysql_query("update partidos set goles_local=$gol_local[$i] where (id_jornada=$jornada and id_local=$y)");
            
mysql_query("update partidos set goles_visitante=$gol_visitante[$i] where (id_jornada=$jornada and id_local=$y)");
            
$i++;
        }
    }
?>

<body>
</body>
</html>