2
Good morning!! I’m in need of some help. In the code below, I submit a file .txt
delimited by ";"
. However, within the While
, in the array, I would like to include a condition, example:
while ( $linha = mysql_fetch_array ( $select ) ) { $conteudo = "
if{$_SESSION[nivelAcesso]==3{
$linha[sap];
$linha[descricao];
}
$linha[segmento];
<?php
header ( 'Content-type: text/plain' );
header ( 'Content-Disposition: attachment; filename="EQUIPAMENTOS_DETALHADOS_' . $date . '.txt"' );
$NOME_ARQUIVO = "EQUIPAMENTOS_DETALHADOS.txt";
?>
<?php
$select = mysql_query ( "SELECT materiais.sap,materiais.descricao,materiais.segmento,descricaoRegiao,estoque.serial, estoque.sim_card, estoque.cas_id ,DATE_FORMAT(estoque.data_cadastro,'%d/%m/%Y') as dataCadastro,Status_equipamento,estoque.notaFiscal from estoque inner join materiais on estoque.id_material=materiais.id inner join regioes_estoque on estoque.regional=regioes_estoque.regiao where materiais.almoxarifado='$_SESSION[almoxarifado]' and estoque.serial <> ' ' and estoque.serial not in (select serial from movimento)" ) or die ( mysql_error () );
$saida = fopen ( "EQUIPAMENTOS_DETALHADOS.txt", "a+" );
echo "COD.SAP;DESCRICAO;SEGMENTO;DESCRICAO_REIGAO;SERIAL;SIM_CARD;CAS_ID;DATA_CADASTRO;STATUS_EQUIPAMENTO;NOTA_FISCAL \n";
while ( $linha = mysql_fetch_array ( $select ) ) {
$conteudo = "$linha[sap];$linha[descricao];$linha[segmento];$linha[descricaoRegiao];$linha[serial];$linha[sim_card];$linha[cas_id];$linha[dataCadastro];$linha[Status_equipamento];$linha[notaFiscal]; \n";
$result = fputs ( $saida, $conteudo );
echo $conteudo;
}
;
fclose ( $saida );
unlink ( $NOME_ARQUIVO );
?>
Tiago your code is very confused. Because there is PHP code inside the string
$conteudo
?– Jorge B.
Jorge, The first example is what I would like to see if it is possible to do. I need to include a condition within the
mysql_fetch_array
, for when meeting this condition, it include two more information in the file.txt
generated. I could understand?– Tiago Martins
James you can not by
$conteudo = "
and then putting code in, when you open the quotes you are starting a string, everything inside will be interpreted as such. You can concatenate string with a dot.
thus:$conteudo = $conteudo. "algo mais a acrescentar";
or alternatively the simplified$conteudo .= "algo mais a acrescentar";
. Try to learn a little more PHP and programming to understand these initial concepts.– Jorge B.