I need to insert multiple records in a mysql table, from another table, but only the first record in the table is inserted my code is as follows
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Conectado a la base de datos correctamente";
//Obtener checadas desde el biometrico
$asistencia = $zk->getAttendance();
foreach($asistencia as $key=>$valor) {
$id = $valor[1];
foreach ($conn->query("SELECT * FROM usuariosBiometrico WHERE id=".$id) as $dato) {
$chofer = $dato['usuario'];
}
$fecha = date( "Y-m-d", strtotime( $valor[3] ) );
$hora = date( "H:i:s", strtotime( $valor[3] ) );
$datosInsertar = array(
'chofer' => $chofer,
'fecha' => $fecha,
'hora' => $hora
);
echo json_encode($datosInsertar);
$sql = "INSERT INTO checadas (chofer, fecha, hora) VALUES ('".implode("', '", $datosInsertar)."')";
}
if (mysqli_query($conn, $sql)) {
echo "Registros insertados correctamente";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
in the JSON if all records are shown but when you insert them into the database, only one record is inserted What can I do to insert all the records in the corresponding fields?