Create a history table with trigger or html, mysql php

1

I have a table of people and I want to make a history of changes in a table only if I change the level or year that is inserted into a table called history, I do not want it to be inserted if I update its address. ONLY if I update your level Y year, I have NO idea how to CREATE THE HISTORY and the trigger correctly.

CREATE TRIGGER  actualize_historial AFTER  UPDATE ON personal
FOR EACH ROW
INSERT INTO historial  id_cliente=id , nivel=NEW.nivel, anio=NEW.anio ;

This is what I can think of, with trigger

on the other hand I would like to do it manually pass them make a list and pass them by selecting a check of the data that I want to create the history to click on a button and pass a lot of data. But this is not how to program it (check and button) to pass them as a group.

<?php
    require('conexion.php');

    $query="SELECT *  FROM personal";

    $resultado=$mysqli->query($query);

?>




<table>
            <thead>
                <tr class="centro">
                    <td>id_cliente</td>
                    <td>Nombre</td>
                    <td>Género</td>
                    <td>dirección</td>
                    <td>nivel</td>
                    <td>año</td>
                    <td>accion</td>
                </tr>
                <form>
                <tbody>


                    <?php while($row=$resultado->fetch_assoc()){ 
                            echo ' 

                        <tr>
                        <td hidden><input name="idEnumera[]" value="'.$row['id_cliente'].'" /></td>

                            <td><input type="number" name="idEmpl['.$row['id_cliente'].']" value="'.  $row['id_cliente'] .'"  /></td>
                            <td><input type="text" name="ciudad['.$row['id_cliente'].']" value="'.  $row['nombre'] .'"  /></td>
                            <td><input type="text" name="ciudad['.$row['id_cliente'].']" value="'.  $row['genero'] .'"  /></td>
                            <td><input type="text" name="cargo['.$row['id_cliente'].']" value="'.  $row['direccion'] .'"  /></td>
                            <td><input type="text" name="mail['.$row['id_cliente'].']" value="'.  $row['nivel'] .'"  /></td>
                            <td><input type="text"  value="'.  $row['id_cliente'] .'" value="'.  $row['anio'] .'"  /></td>

                            <td><input type="checkbox"  value="'.  $row['id_cliente'] .'" value=""  /></td>



                        </tr>


                        '; 

                     } ?>



                </tbody>
                    <input type="submit" name="Crear historial" value="pasarlos al historial" class="btn btn-info col-md-offset-9">
                    </form>
            </table>
    
asked by Carlos 13.04.2018 в 00:16
source

1 answer

2

This question is already answered here, I hope it will help: Update only if you change a field

What you would have to do is evaluate if the new field is different from the old field:

IF NEW.campo <> OLD.campo or NEW.b THEN  
  INSERT INTO historial  id_cliente=id , nivel=NEW.nivel, anio=NEW.anio ;
END IF
    
answered by 13.04.2018 / 00:37
source