This script generates a txt extracted from MySQL:
<?php
include "conexao.php";
$querymail = mysql_query("select cod,nome,tipo,valor from livros");
fopen("txt/relatorio.txt", "w+");
while($data = mysql_fetch_array($querymail)) {
$log = str_pad($data[0], 10, "0", STR_PAD_LEFT);
$log1 = str_pad($data[1], 15, " ", STR_PAD_RIGHT);
$log2 = str_pad($data[2], 10, "0", STR_PAD_LEFT);
$log3 = str_pad($data[3], 10, "0", STR_PAD_LEFT);
if (!$savelog = fopen('txt/relatorio.txt', "a"))
{ exit; }
if (!fwrite($savelog, $cod3. $log. $log1. $log2. $cod4b. $cod5b. $cod6b. $log3. $cod7b. $cod8b."\r\n" ))
{ exit; fclose($savelog); }
}
?>
The generated report looks like this:
001 LIVRO01 AAAA 3200
002 LIVRO02 AAAA 3200
003 LIVRO03 AAAA 3200
004 LIVRO04 AAAA 3200
I need to insert at the top of the txt file the date and time (081120161226) and in the footer the total workbook and total value, like this:
081120161226
001 LIVRO01 AAAA 3200
002 LIVRO02 AAAA 1200
003 LIVRO03 AAAA 1000
004 LIVRO04 AAAA 2500
04 6900