How it could show the history of an ID in PHP mysql

0

I would like to make a web system which shows me the X client (ID) history and I have the complete crud but at the point of how to create a history as the client asks me unfortunately I do not know how it is done.

Explanation in detail of what I need:

The customer is a tire dealer and needs that when for example I store a Data and which is identified with the ID for example, it needs that when they click on a Data already stored in a database it shows the history of that data.

Example in production:

Save JUAN on Wednesday - > and he made two entry and exit in his work the day the time and date

Code:

Update.php

<?php
//Compara para ver si existe algo como indica el codigo si no existe un POST
//Mandame hasta el Eelse

if(!empty($_POST)){

/*Compara para ver si los campos agreados al POST (input en el html) esta vacion y si lo estan me manda al else y si no ejecuta la connecion*/
    if(isset($_POST["name"]) &&isset($_POST["lastname"]) &&isset($_POST["email"]) &&isset($_POST["address"]) &&isset($_POST["phone"])){

        if($_POST["name"]!=""&& $_POST["lastname"]!=""&&$_POST["address"]!=""){

    //crea la conexion a la base de datos 
            include "conexion.php";

            /*Ejecuta update a la tabla atravez de la variable $sql y agrega los datos*/
            $sql = "update person set name=\"$_POST[name]\",lastname=\"$_POST[lastname]\",email=\"$_POST[email]\",address=\"$_POST[address]\",phone=\"$_POST[phone]\" where id=".$_POST["id"];

            //se insertan los datos
            $query = $con->query($sql);
            //si ya se termino osea ni no manda nada y todo salio bien me muestra el IF
            if($query!=null){
                print "<script>alert(\"Actualizado exitosamente.\");window.location='../ver.php';</script>";

                //sino me sale el else
            }else{
                print "<script>alert(\"No se pudo actualizar.\");window.location='../ver.php';</script>";

            }
        }
    }
}
?>

add.php

<?php

if(!empty($_POST)){
    if(isset($_POST["name"]) &&isset($_POST["lastname"]) &&isset($_POST["email"]) &&isset($_POST["address"]) &&isset($_POST["phone"])){
        if($_POST["name"]!=""&& $_POST["lastname"]!=""&&$_POST["address"]!=""){
            include "conexion.php";

            $sql = "insert into person(name,lastname,email,address,phone,created_at) value (\"$_POST[name]\",\"$_POST[lastname]\",\"$_POST[email]\",\"$_POST[address]\",\"$_POST[phone]\",NOW())";
            $query = $con->query($sql);
            if($query!=null){
                print "<script>alert(\"Agregado exitosamente.\");window.location='../ver.php';</script>";
            }else{
                print "<script>alert(\"No se pudo agregar.\");window.location='../ver.php';</script>";

            }
        }
    }
}
?>

Search.php

<?php

include "conexion.php";

$user_id=null;
$sql1= "select * from person where name like '%$_GET[s]%' or lastname like '%$_GET[s]%' or address like '%$_GET[s]%' or email like '%$_GET[s]%' or phone like '%$_GET[s]%' ";
$query = $con->query($sql1);
?>

<?php if($query->num_rows>0):?>
<table class="table table-bordered table-hover">
<thead>
    <th>Nombre</th>
    <th>Apellido</th>
    <th>Email</th>
    <th>Direccion</th>
    <th>Telefono</th>
    <th></th>
</thead>
<?php while ($r=$query->fetch_array()):?>
<tr>
    <td><?php echo $r["name"]; ?></td>
    <td><?php echo $r["lastname"]; ?></td>
    <td><?php echo $r["email"]; ?></td>
    <td><?php echo $r["address"]; ?></td>
    <td><?php echo $r["phone"]; ?></td>
    <td style="width:150px;">
        <a href="./editar.php?id=<?php echo $r["id"];?>" class="btn btn-sm btn-warning">Editar</a>
        <a href="#" id="del-<?php echo $r["id"];?>" class="btn btn-sm btn-danger">Eliminar</a>
        <script>
        $("#del-"+<?php echo $r["id"];?>).click(function(e){
            e.preventDefault();
            p = confirm("Estas seguro?");
            if(p){
                window.location="./php/eliminar.php?id="+<?php echo $r["id"];?>;

            }
        });
        </script>
    </td>
</tr>
<?php endwhile;?>
</table>
<?php else:?>
    <p class="alert alert-warning">No hay resultados</p>
<?php endif;?>

I think that in the previous one, the problem is not because I think so.

table.php - where it shows the data

<?php

include "conexion.php";

$user_id=null;
$sql1= "select * from person";
$query = $con->query($sql1);
?>

<?php if($query->num_rows>0):?>
<table class="table table-bordered table-hover">
<thead>
    <th>Nombre</th>
    <th>Apellido</th>
    <th>Email</th>
    <th>Direccion</th>
    <th>Telefono</th>
    <th></th>
</thead>
<?php while ($r=$query->fetch_array()):?>
<tr>
    <td><?php echo $r["name"]; ?></td>
    <td><?php echo $r["lastname"]; ?></td>
    <td><?php echo $r["email"]; ?></td>
    <td><?php echo $r["address"]; ?></td>
    <td><?php echo $r["phone"]; ?></td>
    <td style="width:150px;">
        <a href="./editar.php?id=<?php echo $r["id"];?>" class="btn btn-sm btn-warning">Editar</a>
        <a href="#" id="del-<?php echo $r["id"];?>" class="btn btn-sm btn-danger">Eliminar</a>
        <script>
        $("#del-"+<?php echo $r["id"];?>).click(function(e){
            e.preventDefault();
            p = confirm("Estas seguro?");
            if(p){
                window.location="./php/eliminar.php?id="+<?php echo $r["id"];?>;

            }

        });
        </script>
    </td>
</tr>
<?php endwhile;?>
</table>
<?php else:?>
    <p class="alert alert-warning">No hay resultados</p>
<?php endif;?>
    
asked by simon 04.01.2017 в 00:45
source

3 answers

2

To have the history you simply have to create as many records as there are events. In the case of Juan, it would be:

|tabla_persona |  tabla_evento |
|- id          |  id_evento    |  
|- nombre      |  id_persona   |
                  evento       |

Establishing a relationship of 1 to many (1 person has many events)

It will then depend on your application that the operation add add a new event to the id of the person, in this case Juan. And the query would look something like:

SELECT * FROM tabla_evento WHERE id_persona = 'IDJUAN';
    
answered by 29.07.2017 / 10:18
source
0

I think you should first diagram the person tables and the ones you need to audit by adding the ref of the id of the first one. There you would have ex:

person:
**id**
name
date_insert
date_update

activity
id
**id_person**
accion
date_time

Where the fk is id_person that relates the activity table to the person table

    
answered by 05.01.2017 в 16:54
-1

If with history you refer to everything the person does within your application, the idea is if you use a framework, from a base controller, You must send all the data to a table or file, for example to distinguish that user, this is a sample of what you realize on occasion.

public function bitacora($module, $action){
    $bitacora = new Bitacora(array(
    'id_usuario' => $this->data['id_usuario'],
    'modulo' => $module,
    'accion' => $action,
    'parametros' => http_build_query(Input::except('_token'),'',' ,')
    ));
    $bitacora->save();
}
    
answered by 04.01.2017 в 01:34