English 中文(简体)
Table of calificacions in php and laravel
原标题:

I created a table in order to show the name of the students, name of the subjects and the grade of the subject of the student I have the next code: this is the index part

<form action="{{ route( Formatos.index ) }}" method="GET">
    <select name="carrera_id">
        <option value="">Seleccione una carrera</option>
        @foreach ($carreras as $carrera)
            <option value="{{ $carrera->IdCarreras }}">{{ $carrera->NombreCarrera}}</option>
        @endforeach
    </select>
    <select name="Semestre_id">
        <option value="">Seleccione un semestre</option>
        @foreach ($semestres as $semestre)
            <option value="{{ $semestre->IdSemestres }}">{{ $semestre->Semestre}}</option>
        @endforeach
    </select>
    <select name="turno">
        <option value="">Seleccione un turno</option>
        <option value="Matutino">Matutino</option>
        <option value="Vespertino">Vespertino</option>
    </select>
    <select name="salon">
        <option value="">Seleccione un salon</option>
        <option value="Salon A">Salon A</option>
        <option value="Salon B">Salon B</option>
        <option value="Salon C">Salon C</option>
        <option value="Salon D">Salon D</option>
        <option value="Salon E">Salon E</option>
        <option value="Salon F">Salon F</option>
        <option value="Salon G">Salon G</option>
        <option value="Salon H">Salon H</option>
 </select>
    <select name="U1">
        <option value="U1">Seleccione una unidad</option>
            <option value="U1">U1</option>
            <option value="U2">U2</option>
            <option value="U3">U3</option>
            <option value="U4">U4</option>
            <option value="U5">U5</option>
    </select>
    <button type="submit">Mostrar</button>
</form>
                        
                          @csrf
                            <table id="tabla_datos" class="table table-striped mt-2">
                                <thead style="background-color:#6777ef"> 
                                    <tr>
                                        <td rowspan="2" > ```


``@if ($materias->count() > 0)
    <table style=" width: 1180px;">
        <thead>
            <tr style=" width: 110px;">
            <td style="background-color: gray; color:#fff; width: 80px;"> Asignatura</td>
                @foreach ($materias as $materia)
                    <th style="background-color: #18316B; color:#fff; width: 90px;">{{ $materia->NombreMateria }}</th>
                @endforeach
                <th style="background-color: #18316B; color:#fff;width: 80px;"  colspan="6">Observaciones</th>
            </tr>
        </thead>
        <thead>
            <tr>
            <td style="background-color: gray; color:#fff;"> Unidades</td>
            <td  style="background-color: #18316B; color:#fff;">
              <select id = "grade-selector" class="form-control" style="width: 80px;">
                <option value="U1">U1</option>
                <option value="U2">U2</option>
                <option value="U3">U3</option>
                <option value="U4">U4</option>
                <option value="U5">U5</option>
              </select>
            </td> 
            <td style="background-color: #18316B; color:#fff;">
              <select  id = "grade-selector2" class=" form-control" style="width: 80px;" >
                <option value="U1">U1</option>
                <option value="U2">U2</option>
                <option value="U3">U3</option>
                <option value="U4">U4</option>
                <option value="U5">U5</option>
              </select>
            </td> 
            <td style="background-color: #18316B; color:#fff;">
              <select id="grade-selector3" class=" form-control" style="width: 80px;">
                <option value="U1">U1</option>
                <option value="U2">U2</option>
                <option value="U3">U3</option>
                <option value="U4">U4</option>
                <option value="U5">U5</option>
              </select>
            </td> 
            <td style="background-color: #18316B; color:#fff;">
              <select id = "grade-selector4" class=" form-control" style="width: 80px;">
                <option value="U1">U1</option>
                <option value="U2">U2</option>
                <option value="U3">U3</option>
                <option value="U4">U4</option>
                <option value="U5">U5</option>
              </select>
            </td> 
            <td style="background-color: #18316B; color:#fff;">
              <select id = "grade-selector5" class=" form-control" style="width: 80px;">
                <option value="U1">U1</option>
                <option value="U2">U2</option>
                <option value="U3">U3</option>
                <option value="U4">U4</option>
                <option value="U5">U5</option>
              </select>
            </td> 
            <td style="background-color: #18316B; color:#fff;">
              <select id = "grade-selector6" class=" form-control" style="width: 80px;">
                <option value="U1">U1</option>
                <option value="U2">U2</option>
                <option value="U3">U3</option>
                <option value="U4">U4</option>
                <option value="U5">U5</option>
              </select>
            </td> 
            <td style="background-color: #18316B; color:#fff; width: 1000px;"> </td>
            </tr>
@endif
@if ($alumnos->count() > 0)
    <table>
        <tbody>
            @foreach ($alumnos as $index => $alumno)
                @if (isset($estudiantes[$index]) && isset($calificaciones[$index]))
                    <tr>
                        <td  style="background-color: #fff; color:black; width: 110px; text-align: center;">  {{ $estudiantes[$index]->name }}</td>
                        @foreach ($calificaciones as $calificacion)
                        <td class="grade-cell U1" style="background-color: #fff; color:black; width: 180px; text-align: center;">{{ $calificacion->U1 }}</td>
                        @endforeach
                        @foreach ($calificaciones as $calificacion)
                        <td class="grade-cell2 U2" style="background-color: #fff; color:black; width: 180px; text-align: center;">{{ $calificacion->U2 }}</td>
                        @endforeach
                        @foreach ($calificaciones as $calificacion)
                        <td class="grade-cell U3" style="background-color: #fff; color:black; width: 180px; text-align: center;">{{ $calificacion->U3 }}</td>
                        @endforeach
                        <td style="background-color: #fff; color:black; width: 130px;">
                            <textarea id="observaciones-{{ $index }}" name="observaciones[]" rows="3" cols="25">{{ $formatos[$alumno->Alumno_id]->observaciones ??    }}</textarea>
                            <button onclick="guardarComentarios({{ $alumno->Alumno_id }})">Guardar</button>
                        </td>
                    </tr>
                    
                @endif
            @endforeach
        </tbody>
        
    </table>
@endif
 @section( scripts )
                                            <script>
                                                function printTable()
            {
                var table = document.getElementById("tabla_datos");

                var printWindow = document.createElement( iframe );
                printWindow.style.position =  absolute ;
                printWindow.style.top =  -10000px ;
                printWindow.style.left =  -10000px ;

                document.body.appendChild(printWindow);

                printWindow.contentDocument.write( <html><head><title>Imprimir tabla</title> );
                printWindow.contentDocument.write( </head><body> );
                printWindow.contentDocument.write(table.outerHTML);
                printWindow.contentDocument.write( </body></html> );

                printWindow.contentWindow.print();

                setTimeout(function () 
                { 
                    document.body.removeChild(printWindow);
                }, 1000);
            }
    function guardarComentarios(alumnoId) {
        var comentarios = document.getElementById( comentarios_  + alumnoId).value;

        // Realiza una petición AJAX para guardar los comentarios en el backend
        // Puedes utilizar jQuery o la librería nativa fetch() para realizar la petición

        // Ejemplo con jQuery:
        $.ajax({
            method:  POST ,
            url:  /Formatos/agregarComentarios ,
            data: {
                alumno_id: alumnoId,
                comentarios: comentarios
            },
            success: function(response) {
                alert( Comentarios guardados exitosamente );
            },
            error: function(error) {
                alert( Error al guardar los comentarios );
            }
        });
    }
    $( #grade-selector ).on( change , function() {
        var selectedGrade = $(this).val();

        // Hide all grade cells
        $( .grade-cell ).hide();
        $( .grade-cell2 ).hide();

        // Show the selected grade cell
        $( .  + selectedGrade).show();
    });
    $( #grade-selector ).trigger( change ); 
                                            </script>
                                            @endsection 


this is the controller of Calificacion. I have created the index function in order to show the name of the student and of the subject, and the grade of the student and subject. In the index view, I created drop down list where I can choose the career, semester, classroom and schedule, and inside the table I created six drop down list where it shows the name of the subject

class FormatoController extends Controller
{
    // $data = Process::with( user )->findOrFail(Auth::id()); 
    /**
     * Display a listing of the resource.
     *
     * @return IlluminateHttpResponse
     */

     public function index(Request $request)
{
    $query = Calificacion::select( Alumno_id )->get();
    $carreras = Carrera::all();
    $comentarios = Formato::all();
    $calificaciones = Calificacion::all();
    $maestros = Maestro::all();
    $turnos = Calificacion::all();
    $salones = Calificacion::all();
    $semestres = Semestre::all();
    $estudiantes = Calificacion::join( users ,  users.id ,  = ,  calificacions.Alumno_id )
    ->select( users.name )
    ->distinct()
    ->get();

    

    // Obtener la lista de alumnos distintos
    $alumnos = Calificacion::select( Alumno_id )->distinct()->get();

    // Obtener la lista de materias relacionadas con las calificaciones
    $calificaciones = Calificacion::first();
    $calificaciones = Calificacion::with( materias ,  calificaciones )->get();
    $calificaciones = Calificacion::select( Alumno_id ,  U1 ,  Materia_id ,  U2 ,  U3 , U4 , U5 , U6 , U7 ,  U8 ,  U9 ,  U10 , U11 , U12 )->distinct()->get();

    // Obtener los formatos relacionados con los alumnos
    $formatos = Formato::whereIn( nombre , $alumnos->pluck( Alumno_id ))->get()->keyBy( Alumno_id );

    // Obtener los filtros de búsqued
    $semestreId = $request->input( Semestre_id );
    $maestroId = $request-> input( Maestro_id );
    $materiaId = $request -> input( Materia_id );
    $turnoId = $request -> input( turno );
    $salonId = $request -> input( salon );
    $calificacionId = $request->input( U1 );
    $calificacionId = $request->input( U2 );
    $calificacionId = $request->input( U3 );
    $calificacionId = $request->input( U4 );
    $calificacionId = $request->input( U5 );
    $calificacionId = $request->input( U6 );
    $calificacionId = $request->input( U7 );
    $calificacionId = $request->input( U8 );
    $calificacionId = $request->input( U9 );
    $calificacionId = $request->input( U10 );
    $calificacionId = $request->input( U11 );
    $calificacionId = $request->input( U12 );

     // Filtrar por carrera seleccionada
    if (request()->has( carrera_id )) {
        $carreraId = request( carrera_id );
        $alumnos = Calificacion::where( Carrera_id , $carreraId)->get(); // Obtener los alumnos de la carrera seleccionada
        $materias = Materia::where( carrera_id , $carreraId)->get(); // Obtener las materias de la carrera seleccionada


        if ($semestreId) {
            $materias = $materias->where( semestre_id , $semestreId);
        }
        if ($calificacionId) {
            $calificaciones = $calificaciones->where( U1 , U2 , U3 , U4 , U5 , U6 , U7 ,  U8 ,  U9 ,  U10 , U11 , U12 , $calificacionId);
            $calificaciones= Calificacion::where( Materia_id , $calificacionId)
            ->where( U1 , $calificacionId)
            ->get();

            foreach ($calificaciones as $calificacion) {
                $calificacion->U1;
                $calificacion->U2;
                $calificacion->U3;
                $calificacion->U4;
                $calificacion->U5;
            }
            $materias= Calificacion::where( Materia_id , $calificacionId)
            ->where( U1 , $calificacionId)
            ->get();

            $materias = $materias->where( U1 , U2 , U3 , U4 , U5 , U6 , U7 ,  U8 ,  U9 ,  U10 , U11 , U12 , $calificacionId);
            

            $alumnos = $alumnos->where( U1 , U2 , U3 , U4 , U5 , U6 , U7 ,  U8 ,  U9 ,  U10 , U11 , U12 , $calificacionId);
            
        }
        if ($turnoId) {
            $semestres = $semestres->where( turno , $turnoId);
            $materias = $materias->where( turno , $turnoId);
            $alumnos = $alumnos->where( turno , $turnoId);
            $alumnos= Calificacion::where( turno , $turnoId)
            ->get();
            $semestres= Calificacion::where( turno , $turnoId)
            ->get();
            $materias= Calificacion::where( turno , $turnoId)
            ->get();
        }
        if ($salonId) {
            $semestres = $semestres->where( salon , $salonId);
            $alumnos= Calificacion::where( salon , $salonId)
            ->get();
            $semestres= Calificacion::where( salon , $salonId)
            ->get();
            $materias= Calificacion::where( salon , $salonId)
            ->get();
        
            $materias = $materias->where( salon , $salonId);
            $alumnos = $alumnos->where( salon , $salonId);
        }

        if ($maestroId)
        {
            $maestros = $maestros->where( Maestro_id , $maestroId);
        }


    } else {
        $alumnos = collect(); // Crear una colección vacía de alumnos
        $materias = collect(); // Crear una colección vacía de materias
        $semestres = collect();
        $calificaciones = collect();// Crear una colección vacía de calificaciones
        $maestros = collect();
        $calificacionesPorUnidad = [];
    }
    


    $calificaciones = Calificacion::with( materias )->get();
    $calificaciones->each(function ($calificacion) {
        $alumno = optional(Calificacion::find($calificacion->Alumno_id));
        $calificacion->alummos = $alumno->Alumno_id ?? null;
        $calificacion->materias = optional(Materia::find($calificacion->Materia_id))->NombreMateria;
    });
    // Filter calificaciones by selected units
    
    $formatos = Formato::paginate(10);
    return view( Formatos.index ,compact( carreras ,  alumnos ,  materias ,  formatos ,  estudiantes ,  semestres ,  calificaciones ,  maestros ,  turnos ,  salones ));
}

Route Route::get( /Formatos ,[ FormatoController::class, index ])->name( Formatos.index );

When I choose for example U1, it only works on one drop down list and only shows like this

enter image description here

When I have this in the database in phpmyadmin

enter image description here

So I don t know what to change or correct

问题回答

暂无回答




相关问题
what is wrong with this mysql code

$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How can I know if such value exists in database? (ADO.NET)

For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签