0
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 is thus:
001 LIVRO01 AAAA 3200
002 LIVRO02 AAAA 3200
003 LIVRO03 AAAA 3200
004 LIVRO04 AAAA 3200
I need to enter at the top of the txt file the date and time (081120161226) and at the bottom the total book and total value, so:
081120161226
001 LIVRO01 AAAA 3200
002 LIVRO02 AAAA 1200
003 LIVRO03 AAAA 1000
004 LIVRO04 AAAA 2500
04 6900
I tested fwrite, but I couldn’t cross-reference with while... Do you have an example? <? php $Fp = fopen('data.txt', 'w'); fwrite($Fp, '1'); fwrite($Fp, 'or'); fwrite($Fp, '2'); fclose($Fp); // the content of 'data.txt' will be 1ou2! ?>
– checktech