Show Ratings according to PHP MYSQL subject

0

Good morning Community. I have this student report card by subject But I have tried to make the notes go horizontally according to the subject and not vertically according to the image. I have not been able to solve this concern.

The code I occupy is

class Consultar_Materias extends Conexion{
    private $consulta;
    private $fetch;

    function __construct($codigo){
        parent::__construct();
        $this->consulta = $this->conexion_db->query("SELECT * FROM materia WHERE id='$codigo'");
        $this->fetch = mysqli_fetch_array($this->consulta);
    }

    function consultar($campo){
        return $this->fetch[$campo];
    }
}

this code is the one on the page:

if(!empty($_GET['cod']) and !empty($_GET['periodo'])){
    $id_periodo=$_GET['periodo'];
    $id_alumno=$_GET['cod'];
    $oPeriodo=new Consultar_Periodo($id_periodo);
    $oAlumno=new Consultar_Alumno($id_alumno);  
    $nombre_alumno=$oAlumno->consultar('nombre');

    $oGrado= new Consultar_Grado($oAlumno->consultar('grado'));
    $oSalon= new Consultar_Salon($oAlumno->consultar('salon'));

    $nombre_salon=$oSalon->consultar('nombre');
    $nombre_grado=$oGrado->consultar('nombre');

    $oEmpresa= new Consultar_Empresa('1');

    $dir='Direccion: '.$oEmpresa->consultar('direccion').'<br>'.$oEmpresa->consultar('pais').' - Viña del Mar';

    $regresar=$oAlumno->consultar('salon');#5
}else{
    header('Location:error.php');
}
</table>
      <br />
      <table width="90%" rules="all" border="1" style="font-family:Arial, Helvetica, sans-serif">
      <tr>
        <td>
            <center><strong>Nombre del Alumno</strong><br /><?php echo $nombre_alumno; ?></center>
        </td>
        <td width="25%"><center><strong>Curso</strong><br /><?php echo $nombre_grado; ?></center></td>
        <td width="25%"><center><strong>Sala<br /></strong><?php echo $nombre_salon; ?></center></td>
      </tr>
      <tr>
        <td colspan="3"><br /><center><strong>Informe del Periodo <?php echo $oPeriodo->consultar('nombre'); ?> Semestre</strong></center></td>
      </tr>
      </table>
      <bR />
      <table width="90%" rules="all" border="1" style="font-family:Arial, Helvetica, sans-serif">
      <tr>
        <td width="50%"><strong><center>Materia</center></strong></td>
        <td width="50%"><strong><center>Calificación</center></strong></td>
      </tr>
      <?php 
        $pa=mysqli_query($conexion,"SELECT * FROM notas WHERE alumno='$id_alumno' and periodo='$id_periodo' ORDER BY materia");             
        while($row=mysqli_fetch_array($pa)){
            $oMateria=new Consultar_Materias($row['materia']);
      ?>
      <tr>
        <td><center><?php echo $oMateria->consultar('nombre'); ?></center></td>
        <td><center><?php echo $row['valor']; ?></center></td>
      </tr>
      <?php } ?>
    </table>

How can I put each grade horizontally according to each subject?

Mathematics | 40 | 50 | 60 | 70 |

Language | 55 | 60 | 60 |

Thanks

    
asked by Francisco 02.06.2017 в 17:35
source

1 answer

1
</table>
  <br />
  <table width="90%" rules="all" border="1" style="font-family:Arial, Helvetica, sans-serif">
  <tr>
    <td>
        <center><strong>Nombre del Alumno</strong><br /><?php echo $nombre_alumno; ?></center>
    </td>
    <td width="25%"><center><strong>Curso</strong><br /><?php echo $nombre_grado; ?></center></td>
    <td width="25%"><center><strong>Sala<br /></strong><?php echo $nombre_salon; ?></center></td>
  </tr>
  <tr>
    <td colspan="3"><br /><center><strong>Informe del Periodo <?php echo $oPeriodo->consultar('nombre'); ?> Semestre</strong></center></td>
  </tr>
  </table>
  <bR />
  <table width="90%" rules="all" border="1" style="font-family:Arial, Helvetica, sans-serif">
  <tr>
    <td width="50%"><strong><center>Materia</center></strong></td>
    <td width="50%"><strong><center>Calificación</center></strong></td>
  </tr>
  <?php 


  // creo un contador que nos servirá para más adelante
  $cont = 0;
    $pa=mysqli_query($conexion,"SELECT * FROM notas WHERE alumno='$id_alumno' and periodo='$id_periodo' ORDER BY materia");             
    while($row=mysqli_fetch_array($pa)){

        // TE MOSTARÁ EL NOMBRE DE LA MATERIA UNA SOLA VEZ PUESTO QUE CONTADOR LO HEMOS INICIADO A 0
        if($cont === 0){
            $materia = $row['materia']
            echo '<td>' . $materia;
            $cont++;
        }

        // TE MUESTRA LAS NOTAS PARA ESA MATERIA
        echo  $row['valor'] . ' | ';

        //aquí comparamos si la materia sigue siendo la misma o no
        //si es distinta la variable '$materia' cambiará por la siguiente materia y en el primer 'if' nos la mostará
        if($materia !== $row['materia']){
            //cerramos el <td> que hemos abierto al mostrar la materia
            echo '</td>';

            //ahora $materia almacena el nombre de la siguiente materia
            $materia = $row['materia']; 

            //contador a 0 para volver a mostrar el nombre de la nueva materia
            $cont = 0;
        }


  ?>
  <!-- ponemos este </td> aquí ya que cuando se termine el 'while' no entrará en el segundo 'if' i así queda cerrado -->
  </td> 

  <?php } ?>
</table>

Try to see if it works for you, if the code has some syntax error or if you miss an error when executing it, let it know, even this method would have to show you the information as you want

    
answered by 02.06.2017 / 17:57
source