Registration of several data of the same type in a single record linked to php with relation of mysql tables

0

Good I am something new in the programming and I am doubtful with respect to how to do the following, I have a system in php linked to mysql.

I have a record made in php that sends me the data to a table called 'students' which has:

estudiantes
-------------
cedula(key),
apellido,
nombre,
carrera, 
turno, 
seccion, 
email. 

and I want to do in the same way a record of: grupos

but to register a group of students I want you to ask me:

ID_grupo(key) AUTO_INCREMENT, 
proyecto, 
cod_parroquia, 
lugar, 
habitantes, 
cod_periodo. 

These would be data that give me information about the group, once that data is filled by the user:

  • The system should ask me how many students are in the group.
  • Depending on how many there are, so many text boxes in html will be opened to enter nothing but the card.
  • And through that I must take into account all the data entered in the table 'students' example: group ID_grupo=00001 has 4 students, shows me (all information group information) and at the same time all the data of the table 'students' of those 4 that enter in my system so that they would be registered along with that ID_grupo that would be my key field.

    I appreciate any advice, examples, code structure, but what confuses me the most is how the database is with that, the tables and fields, I do not know how to enter several data of the same type in the same record

    here the code:

    <?php
    include ('control.php');
    $boton= $_POST['boton'];
    $idgrupo= $_POST['idgrupo'];
    $num_int= $_POST['num_int'];
    $ced_alum= $_POST['ced_alum'];
    $op= $_POST['op'];
    if ($boton=="Guardar") {
        $sql="insert into grupo ()
        values ('')";
        if (mysql_query($sql)) {
            echo "<script> alert ('Data Almacenda')</script>";
            echo "<script> window.location='registro.php'</script>";
        } else {
            echo "<script> alert ('No Guardado')</script>";
        }
    }
    ?>
    
    <!DOCTYPE html>
    <html>
    <head>
        <title>Registro de grupos</title>
        <meta charset="utf-8">
    </head>
    <body>
    <form method="post" action="">
    
    <h1>Creacion del Grupo:</h1> 
    <p><label>Grupo Nro:</label> <input type="text" name="idgrupo" readonly placeholder="Número predeterminado"></p>
    
    <p>
        <label>Carrera:</label>
        <select name="carrera" required="">
        <option>Seleccionar</option>
        <option>Administración agropecuaria</option>
        <option>Administración de empresas</option>
        <option>Gastronomía</option>
        <option>Informática</option>
        <option>Turismo</option>    
        </select>
    </p>
    
    <p>
        <label>Turno</label>
        <select name="turno">
        <option>Seleccionar</option>
        <option>Matutino</option>
        <option>Vepertino</option>
        <option>Sabatino</option>   
        </select>
    </p>
    
    <p>
        <label>Período académico:</label><input type="text" name="periodo" placeholder="(I-2000)(II-2000)(III-2000)">
    </p>
    <p><label><h1>Integrantes:</h1></label></p>
    <p><label>Numero de integrantes:</label><input type="number" name="op"></p>
    <?php
    switch ($op) {
        case 1:
            // se deben abrir tantas cajas de texto para registro como numeros se ingresen en "Numero de integrantes"
            break;
    
        default:
            break;
    }
    ?>
    # Estás son las cajas de texto que se deben abrir dependiendo de cuantos numeros sean los integrantes, de modo que se ingrese la cedula y ya me tome en cuenta todos los datos ya ingresados en la tabla estudiantes
    <p>
    <label>Cédula: </label><input type="text" name="ced_alumno">
    </p>
    
    <p>
    <label>Cédula: </label><input type="text" name="ced_alumno">
    </p>
    
    <p>
    <label>Cédula: </label><input type="text" name="ced_alumno">
    </p>
    
    <p>
    <label>Cédula: </label><input type="text" name="ced_alumno">
    </p>
    
    <p>
    <label>Cédula: </label><input type="text" name="ced_alumno">
    </p>
    
    <p>
    <label>Cédula: </label><input type="text" name="ced_alumno">
    </p>
    
    <p><input type="submit" name="boton" value="Guardar"></p>
    <p><input type="submit" name="boton" value="Limpiar"></p>
    <p><a href="http://localhost/sercom/menu3.php">Volver</a></p>
       </p>
    
    </form>
    </body>
    </html>
    
        
    asked by Shifter 02.05.2017 в 18:52
    source

    1 answer

    0

    Here's how I solved it, the problem was a duplicity of variables which I did not see how to organize them, in case someone happens to want to make several records of the same type and keep them with a code that they want to enter only once. :

    <?php
    include ('control.php');
    $boton= $_POST['boton'];
    $idgrupo= $_POST['idgrupo'];
    $carrera= $_POST['carrera'];
    $periodo= $_POST['periodo'];
    //------ 1
    $boton1= $_POST['boton1'];
    $ced_alum= $_POST['ced_alum'];
    $nom= $_POST['nom'];
    $ape= $_POST['ape'];
    $turno= $_POST['turno'];
    //------ 2
    $boton2= $_POST['boton2'];
    $ced_alum2= $_POST['ced_alum2'];
    $nom2= $_POST['nom2'];
    $ape2= $_POST['ape2'];
    $turno2= $_POST['turno2'];
    //------ 3
    $boton3= $_POST['boton3'];
    $ced_alum3= $_POST['ced_alum3'];
    $nom3= $_POST['nom3'];
    $ape3= $_POST['ape3'];
    $turno3= $_POST['turno3'];
    //------ 4
    $boton4= $_POST['boton4'];
    $ced_alum4= $_POST['ced_alum4'];
    $nom4= $_POST['nom4'];
    $ape4= $_POST['ape4'];
    $turno4= $_POST['turno4'];
    //------ 5
    $boton5= $_POST['boton5'];
    $ced_alum5= $_POST['ced_alum5'];
    $nom5= $_POST['nom5'];
    $ape5= $_POST['ape5'];
    $turno5= $_POST['turno5'];
    //------ 6
    $boton6= $_POST['boton6'];
    $ced_alum6= $_POST['ced_alum6'];
    $nom6= $_POST['nom6'];
    $ape6= $_POST['ape6'];
    $turno6= $_POST['turno6'];
    $op= $_POST['op'];
    
    
    // Buscar alumno 1
    if ($boton1=="Buscar") {
        # code...
        $sql="Select * from alumno where ced_alum ='$ced_alum'";
        $busqueda=mysql_query($sql);
        if($registro=mysql_fetch_array($busqueda)){
            $ced_alum = $registro['ced_alum'];
            $nom = $registro['nom'];
            $ape = $registro['ape'];
            $turno = $registro['turno'];
    
                }else{
            echo "<script>alert('Registro No existe en el Sistema')</script>";
            }
    }
    // Cierre Alumno 1
    
    // Buscar alumno 2
    if ($boton2=="Buscar") {
        # code...
        $sql="Select * from alumno where ced_alum ='$ced_alum2'";
        $busqueda=mysql_query($sql);
        if($registro=mysql_fetch_array($busqueda)){
            $ced_alum2 = $registro['ced_alum'];
            $nom2 = $registro['nom'];
            $ape2 = $registro['ape'];
            $turno2 = $registro['turno'];
    
                }else{
            echo "<script>alert('Registro No existe en el Sistema')</script>";
            }
    }
    // Cierre Alumno 2
    
    // Buscar alumno 3
    if ($boton3=="Buscar") {
        # code...
        $sql="Select * from alumno where ced_alum ='$ced_alum3'";
        $busqueda=mysql_query($sql);
        if($registro=mysql_fetch_array($busqueda)){
            $ced_alum3 = $registro['ced_alum'];
            $nom3 = $registro['nom'];
            $ape3 = $registro['ape'];
            $turno3 = $registro['turno'];
    
                }else{
            echo "<script>alert('Registro No existe en el Sistema')</script>";
            }
    }
    // Cierre Alumno 3
    
    // Buscar alumno 4
    if ($boton3=="Buscar") {
        # code...
        $sql="Select * from alumno where ced_alum ='$ced_alum4'";
        $busqueda=mysql_query($sql);
        if($registro=mysql_fetch_array($busqueda)){
            $ced_alum4 = $registro['ced_alum'];
            $nom4 = $registro['nom'];
            $ape4 = $registro['ape'];
            $turno4 = $registro['turno'];
    
                }else{
            echo "<script>alert('Registro No existe en el Sistema')</script>";
            }
    }
    // Cierre Alumno 4
    
    // Buscar alumno 5
    if ($boton3=="Buscar") {
        # code...
        $sql="Select * from alumno where ced_alum ='$ced_alum5'";
        $busqueda=mysql_query($sql);
        if($registro=mysql_fetch_array($busqueda)){
            $ced_alum5 = $registro['ced_alum'];
            $nom5 = $registro['nom'];
            $ape5 = $registro['ape'];
            $turno5 = $registro['turno'];
    
                }else{
            echo "<script>alert('Registro No existe en el Sistema')</script>";
            }
    }
    // Cierre Alumno 5
    
    // Buscar alumno 6
    if ($boton6=="Buscar") {
        # code...
        $sql="Select * from alumno where ced_alum ='$ced_alum6'";
        $busqueda=mysql_query($sql);
        if($registro=mysql_fetch_array($busqueda)){
            $ced_alum6 = $registro['ced_alum'];
            $nom6 = $registro['nom'];
            $ape6 = $registro['ape'];
            $turno6 = $registro['turno'];
    
                }else{
            echo "<script>alert('Registro No existe en el Sistema')</script>";
            }
    }
    // Cierre Alumno 6
    if ($boton=="Guardar") {
    
        $sql="insert into grupo values (null, $idgrupo, '$ced_alum', '$nom', '$ape', '$turno')";
            mysql_query($sql);
        $sql2="insert into grupo values (null, $idgrupo, '$ced_alum2', '$nom2', '$ape2', '$turno2')";
            mysql_query($sql2); 
        $sql3="insert into grupo values (null, $idgrupo, '$ced_alum3', '$nom3', '$ape3', '$turno3')";
            mysql_query($sql3);
        $sql4="insert into grupo values (null, $idgrupo, '$ced_alum4', '$nom4', '$ape4', '$turno4')";
            mysql_query($sql4);
        $sql5="insert into grupo values (null, $idgrupo, '$ced_alum5', '$nom5', '$ape5', '$turno5')";
            mysql_query($sql5);
        $sql6="insert into grupo values (null, $idgrupo, '$ced_alum6', '$nom6', '$ape6', '$turno6')";
            mysql_query($sql6);     
        }
    
    
    //Botones Simples --------------------------------------------------------------------
    
    
    if($boton=="Limpiar"){
            echo "<script>window.location='registro_alumno.php'</script>";  
    }
    //------------------------------------------------------------------------------------
    
    
    ?>
    
    <!DOCTYPE html>
    <html>
    <head>
        <title>Registro de grupos</title>
        <link rel="stylesheet" href="css/bootstrap.css" />
        <meta charset="utf-8">
    </head>
    <body>
    <form method="post" action="">
    
    
    <center><h1><font color="blue">Datos de Grupo</font></h1></center>
    
    <table align="center" cellpadding="7" cellspacing="0" border="0">
    
    <tr>
    <td align="right"><Strong>Grupo Nro:</Strong></td> 
    <td><input type="text" name="idgrupo" required placeholder="N° que identificará al grupo" value="<?PHP echo $idgrupo; ?>"></td>
    </tr>
    
    <tr>
    <td align="right"><strong>Carrera:</strong></td>
    <td><input type="text" name="carrera" value="<?php echo $carrera;?>"></td>
    </tr>
    
    <tr>
        <td align="right"><strong>Periodo Academico:</strong></td>
        <td><input type="text" name="periodo" value="<?php echo $periodo;?>"></td>
    </tr>
    
    </table>
    
    <p><label><h1><font color="blue"><center>Integrantes:</center></font></h1></label></p>
    <center>
    <p>
    <label>Cédula: </label><input type="text" name="ced_alum" value="<?PHP echo $ced_alum; ?>"><input type="submit" name="boton1" value="Buscar" class="btn btn-default btn-sm">
    <label>Nombre: </label><input type="text" name="nom" value="<?PHP echo $nom; ?>">
    <label>Apellido: </label><input type="text" name="ape" value="<?PHP echo $ape; ?>">
    <label>Turno: </label><input type="text" name="turno" value="<?PHP echo $turno; ?>">
    </p>
    
    <p>
    <label>Cédula: </label><input type="text" name="ced_alum2" value="<?PHP echo $ced_alum2; ?>"><input type="submit" name="boton2" value="Buscar" class="btn btn-default btn-sm">
    <label>Nombre: </label><input type="text" name="nom2" value="<?PHP echo $nom2; ?>">
    <label>Apellido: </label><input type="text" name="ape2" value="<?PHP echo $ape2; ?>">
    <label>Turno: </label><input type="text" name="turno2" value="<?PHP echo $turno2; ?>">
    </p>
    
    <p>
    <label>Cédula: </label><input type="text" name="ced_alum3" value="<?PHP echo $ced_alum3; ?>"><input type="submit" name="boton3" value="Buscar" class="btn btn-default btn-sm">
    <label>Nombre: </label><input type="text" name="nom3" value="<?PHP echo $nom3; ?>">
    <label>Apellido: </label><input type="text" name="ape3" value="<?PHP echo $ape3; ?>">
    <label>Turno: </label><input type="text" name="turno3" value="<?PHP echo $turno3; ?>">
    </p>
    
    <p>
    <label>Cédula: </label><input type="text" name="ced_alum4" value="<?PHP echo $ced_alum4; ?>"><input type="submit" name="boton4" value="Buscar" class="btn btn-default btn-sm">
    <label>Nombre: </label><input type="text" name="nom4" value="<?PHP echo $nom4; ?>">
    <label>Apellido: </label><input type="text" name="ape4" value="<?PHP echo $ape4; ?>">
    <label>Turno: </label><input type="text" name="turno4" value="<?PHP echo $turno4; ?>">
    </p>
    
    <p>
    <label>Cédula: </label><input type="text" name="ced_alum5" value="<?PHP echo $ced_alum5; ?>"><input type="submit" name="boton5" value="Buscar" class="btn btn-default btn-sm">
    <label>Nombre: </label><input type="text" name="nom5" value="<?PHP echo $nom5; ?>">
    <label>Apellido: </label><input type="text" name="ape5" value="<?PHP echo $ape5; ?>">
    <label>Turno: </label><input type="text" name="turno5" value="<?PHP echo $turno5; ?>">
    </p>
    <p>
    <label>Cédula: </label><input type="text" name="ced_alum6" value="<?PHP echo $ced_alum6; ?>"><input type="submit" name="boton6" value="Buscar" class="btn btn-default btn-sm">
    <label>Nombre: </label><input type="text" name="nom6" value="<?PHP echo $nom6; ?>">
    <label>Apellido: </label><input type="text" name="ape6" value="<?PHP echo $ape6; ?>">
    <label>Turno: </label><input type="text" name="turno6" value="<?PHP echo $turno6; ?>">
    </p>
    
    </center>
    
    
    <table align="center" cellpadding="0" cellspacing="7" border="0">
        <tr>
    <td><div align="right"><input type="submit" name="boton" value="Guardar" class="btn btn-primary"></div></td>
    <td><div align="right"><input type="submit" name="boton" value="Limpiar" class="btn btn-warning"></div></td>
    <td><div align="right"><a href="http://localhost/sercom/menu3.php">Volver</a></div></td>
       </tr>
    </table>
    
    </form>
    </body>
    </html>
    
        
    answered by 11.05.2017 / 06:03
    source