consult all data of 2 columns

2

I need to make a query with php and mysql, the idea is to consult all the data of 2 columns, especially the table, user_id and validity_document.

I want to check all the data to see if a document is expired and if so send an email alerting, I appreciate if you can help me or suggest ideas for the query.

mysql> SELECT id_usuario, vigencia_documento FROM usuario
-id_conductorPrimaria   int(11)         
-nombre_conductorÍndice char(30)    utf8_general_ci     
-cc_conductor   int(11)         
-licencia_conductor int(11)         
-vigencia_conductor date            
-telefono_conductor char(30)    utf8_general_ci     
-email_conductor    varchar(64) utf8_general_ci     
-direccion_conductor    varchar(255)    utf8_general_ci     
-foto_conductor varchar(255)    latin1_swedish_ci       
-status_conductor   tinyint(4)          
-date_added datetime

The data that I need to evaluate is: -conduct_vigencia identify the driver to send an email

    
asked by Juan Bautista 15.07.2018 в 22:59
source

2 answers

0

You must start a database connection method in this case I'll put Mysql

$mysqli = mysqli_init();

$mysqli->real_connect("localhost", "root", "", "nombre_BD");

$sql = "SELECT id_usuario, vigencia_documento FROM usuario";
        $result = $mysqli->query($sql);
        $fila = mysqli_fetch_assoc($result);

while ($fila.length >= 0) {
    if ($fila['vigencia_documento'] == 'valor a comprar') {
        # enviar el correo...
    }
}

in the if you must compare the validity data, either with a date or with a Boolean ...

I hope you serve and mark it as solved By JJ

    
answered by 15.07.2018 в 23:37
0

For these cases of dates, I would recommend you to save them as a Unix date (in seconds, with BIGINT data), it makes comparison and operation on dates much easier. In any case, this happened to you, maybe I can serve you:

$mysqli = new mysqli('localhost', 'usuario', 'contraseña', 'nombre_base_datos');

$sql = "SELECT id_usuario, vigencia_conductor FROM usuario";
$result = $mysqli->query($sql);

while ($fila = mysqli_fetch_assoc($result)) {
   $fecha_vigencia = date_create($fila['vigencia_conductor']);

//En tu caso como esperas que se avise dos dias antes, se agregan dos dias
if ($fecha_vigencia < date_create("now +2 day")) {
    //se envia el correo al id $fila["id_usuario"]
  }
}

I hope it serves you.

    
answered by 16.07.2018 в 00:46