Problem when changing a student's schedule to another

0

Greetings guys, I have had a problem which I explain now: I make student registrations in courses which have their duration, schedule, amounts to pay, and unique payment dates. So far no problem the inscriptions process well, now what happens is that the case is presented that a student wants to change course because it seems better the schedule of the other course, this is because they can be available two equal courses but with different hours or different duration.

Then it turns out that when making that change of schedule I must update the id_curso in the inscribed table by placing the id of the course to which it is going to change. Up there I have no problem.

The drawback comes here: when I update the course id, I must also update the fields of the amounts to be paid and the dates of the table payments_students, these fields I must update with the appropriate data belonging to the course chosen by the student to change . The problem is that the amounts are changing every 3, because there are increases and those things. What I've tried so far is this:

function cambiar_curso($student,$curso){
$mysqli = new mysqli('localhost','root', '' , 'academia');

$query = "UPDATE inscritos SET id_curso = '".$curso."' WHERE id_student = 
'$student'";
$sql = $mysqli->query($query);

$consulta = "SELECT 
cursos_abiertos.duracion,cursos_abiertos.inicio,detalle_cuota.monto FROM 
detalle_cuota INNER JOIN cursos_abiertos 
ON detalle_cuota.id_curso=cursos_abiertos.id WHERE cursos_abiertos.id = 
'$curso'";
$result = mysqli_query($mysqli,$consulta);
while($fila = mysqli_fetch_array($result,MYSQLI_ASSOC)){

$repetir = $fila['duracion'];
$fechas = $fila['inicio'];
$monto = $fila['monto'];
}

$aumento = 0.2;
$concepto = 0;
$aumentaCada = 3;

for($i = 0; $i < $repetir; $i++){
if(($i>0) && ($i % $aumentaCada)==0):
  $monto = $monto*(1+$aumento);
endif;

if($i>0){
    $fechas = date('d-m-Y', strtotime("$primer + 1 month"));
  }
$concepto = $concepto +1;
}

 $query2 = "UPDATE pagos_estudiantes SET id_c = '".$curso."', concepto = 
 '".$concepto."', monto = '".$monto."', fecha_a_pagar = '".$fechas."' 
 WHERE id_i = '$student' AND estado = 0";
 $sql2 = $mysqli->query($query2);

 if($sql>0 && $sql2>0):
  echo 'bien';
 else:
  echo mysqli_error($mysqli);
 endif;
 }

This is the function in which I intend to make those changes, as I said the course id changes them well to the one I have chosen, but the amounts and dates updates the same data to all the rows. This is the result, attached image:

As you can see the concept fields, amount and date do not update them well. Because in concept it must increase of 1 in one, in amount every 3 amounts must increase 20% and in the dates it must increase 1 month each row. I have tried in many ways but without result! What I need is for me to modify those fields according to the data that I bring from the course the student has chosen to change. Please I need help in this, and with this I would almost complete my system. Thank you all. By the way, the field id_i is where I keep the id of the student and the field id_c has the id of the course.

If it's helpful, these are my tables, I accept criticism to improve relations to be able to do this operation in the best way.

Look how my table should be with the data after doing the update, and compare how it is when I make the change, compare the two images, one is the normal registration and the other is when the change with the update :

    
asked by Alejo Mendoza 06.09.2017 в 16:13
source

2 answers

0

With this code you will be able to increase the dates.

<?php

 $repetir = 12; 
 $concepto =0;
 for($i = 0;  $i <  $repetir;  $i++){
    $primer = '2017-09-01';     
    if($i> 0){       
        $fechas = date('d-m-Y', 
                   strtotime("$primer +$i month"));
        echo $fechas . '<br>';
    }    
    $concepto++;
    echo $concepto . '<br>'; 
}
    
answered by 08.09.2017 в 05:32
0
$aum = "SELECT porcentaje FROM aumento";
$a = $mysqli->query($aum);
$row = $a->fetch_assoc();

$aumento = $row['porcentaje'];
$aumentaCada = 3;
$concepto = 0;
$estado = 0;

for($i = 0; $i < $repetir; $i++){
if(($i>0) && ($i % $aumentaCada)==0):
  $monto = $monto*(1+$aumento);
endif;

if($i>0)
{
  $inicio = date('d-m-Y', strtotime("$inicio + 1 month"));
}

$concepto = $concepto +1;
$query2 = "INSERT INTO pagos_estudiantes 
(id_inscripcion,concepto,monto,fecha_a_pagar,estado) VALUES 
('$val2','$concepto','$monto','$inicio','$estado')";
$sql2 = $mysqli->query($query2);
}

Greetings guys, this has been the way I have solved, now they see that query to the percentage, because they have asked me to have the ability to change the amount of the system every 3 monthly payments. Thanks for your help! Greetings

    
answered by 10.09.2017 в 16:35