Condition values of a select to show students that make up a project and students who are not subscribed to a project

0

I have an option to enroll students to a project, previously there was the error that students or students who appeared in other projects could be enrolled several times, so change the sql query.

this form shows the project and below it the students who are registered in the form of a list * juan * pedro * luis.

Work with three tables: Project (proy_id), Student (cedu_alum) and Project_alumno (proy_alum, alum_id)

Modify the select so that it only takes values where the project was null, but it happens that it does not show the students already enrolled in the project, only those that are not, so it is impossible to remove them,

I would like to know how to modify the selection so that it will also show the students belonging to the project that is being modified

SELECT code

function bd_alumno_opciones()
{
$sql = "SELECT cedu_alum, CONCAT(nom1_alum,' ',nom2_alum,' ',ape1_alum,'  ',ape2_alum,' ',cedu_alum)
FROM alumno LEFT JOIN proyecto_alumno ON cedu_alum = alum_id 
WHERE proy_id is null ORDER BY cedu_alum ASC";
$res = sql2options( $sql );
return $res;
}

Code to pass the value of the proy_id to the registration form:

<a class="btn btn-default" onClick="return confirmSav();"    href="modificar_proyecto_alumno.php?proy_id=<?=$proyecto_alumno_temp['proy_id']?>">Modificar</a>

Modification form for students:

<?php
session_start();
if(!isset($_SESSION["user_id"]) || $_SESSION["user_id"]==null){
print "<script>alert(\"Acceso invalido!\");window.location='login.php';    </script>";
}

?>
<html>
<head>
    <title>.: UNEFA - Inscripción de Alumnos :.</title>
    <link rel="stylesheet" type="text/css"     href="bootstrap/css/bootstrap.min.css">
</head>
<body>
<?php include "php/navbar.php"; ?>
<div class="container">
<div class="row">
<div class="col-md-6">
</div>
</div>
</div>
</body>
</html> 
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">    </script>
<script type="text/javascript">
  jQuery(document).ready(function($) {
    // Change es un evento que se ejecuta cada vez que se cambia el valor de un elemento (input, select, etc).
    $('#proyectos').change(function(e) {
      $('#proy_id').val($(this).val());
    });
  });
</script>

<?php
include 'conexion.php';
$proy_id_seleccionado = ($_REQUEST['proy_id']);
$alumno = bd_alumno_opciones();
$proyecto = bd_proyecto_opciones();

include 'cab.php';
?>
<div>
<center>
<h1> Inscripción de Alumnos </h1>
<font size=3 color="red">*</font> <font size =3>Solo se permite que un alumno exista en un proyecto a la vez</font>
<font size=3 color="red">*</font> <font size =3>Campos Obligatorios</font>
</center>
</div>

<form id="frmIns" class="form-horizontal" method="POST"     action="proc_inscripcion4.php" role="form">

    <div class="form-group">
    <label for="proyectos" class="control-label col-lg-2"><font size=3     color="red">*</font>Proyecto:</label>
    <div class="col-lg-5">

        <select class="form-control" name="proyecto" id="proyectos">

        <?php foreach($proyecto as $i=>$proyecto_temp):?>
            <option value="<?=$i?>"><?=$proyecto_temp?></option>
        <?php endforeach; ?>
        </select>

    </div>
</div>

<div class="form-group">
    <div class="control-label col-lg-2"></div>
    <div class="col-lg-5">

        <input type="hidden" name="proy_id" id="proy_id" readonly  value=""     />

    </div>
</div>



   <div class="form-group">
    <label for="alumno" class="col-lg-2 control-label"><font size=3 color="red">*</font>Alumnos:</label>
    <div class="col-lg-5">
        <?php foreach($alumno as $i=>$alumno_temp): ?>
        <div class="checkbox"><label>
        <input type="checkbox" name="alum[]" id="alum_<?=$i?>" value="<?=$i?>"> <?=$alumno_temp?></label></div>
        <?php endforeach; ?>
    </div>
</div>

<div class="form-group">
    <div class="col-lg-2"></div>
    <div class="col-lg-5">
        <button type="submit" class="btn btn-default">Guardar</button>
    </div>
</div>

</form>
<?php
include 'pie.php';
?>
<script src="./libs/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"     charset="UTF-8"></script>
<script src="./libs/bootstrap-datetimepicker/js/locales/bootstrap-    datetimepicker.es.js" charset="UTF-8"></script>
<script src="./libs/jquery.chained.remote.min.js"></script>
<script src="./libs/jquery.validate.js"></script>
<script type="text/javascript">
$(function() {
$('.form_date').datetimepicker({
    language:  'es',
    weekStart: 1,
    todayBtn:  1,
    autoclose: 1,
    todayHighlight: 1,
    startView: 4,
    minView: 2,
    forceParse: 0
});
 $("#frmIns").validate({
    rules: {
       proy_id: {
            required: true,
            range: [1, 9999]
        },
        alum_id: {
            required: true,
        },
    },
         messages: {
                proy_id: {
            required:"Seleccione un proyecto",
            range:"Seleccione un proyecto",
            }
        }
    });
 });

</script>

ERROR:

Warning: Missing argument 1 for bd_alumn_options (), called in C: \ xampp \ htdocs \ Automated Registration and Control System 2016 \ modify_project_alumno.php on line 23 and defined in C: \ xampp \ htdocs \ Automated Registry System and Control 2016 \ conexion.php on line 350

    
asked by Victor Alejandro Alvarado Vilo 14.09.2016 в 02:11
source

1 answer

1

You should add to the condition of the query that the value of the project is the one you are modifying, in addition to being NULL.

Suppose you have the code of the project to be modified in the variable $ proy_id_seleccionado, which you pass as a parameter to the function.

function bd_alumno_opciones($proy_id_seleccionado){
 $sql = "SELECT cedu_alum,";
 $sql .= " CONCAT(nom1_alum,' ',nom2_alum,' ',ape1_alum,' ',ape2_alum,' ',cedu_alum) ";
 $sql .= " FROM alumno LEFT JOIN proyecto_alumno ON cedu_alum = alum_id ";
 $sql .= " WHERE proy_id = $proy_id_seleccionado OR proy_id is null ORDER BY cedu_alum ASC"; 
$res = sql2options( $sql ); 
return $res; }

Note

I do not know what you use to connect to the database, but you could improve the query by making it a prepared query. This, among other things, would prevent you from injecting SQL code.

    
answered by 14.09.2016 / 03:59
source