1
I’ve got all the code you need, but it’s a mistake and it has to do with $i
. how can I correct?
<?php
include('conetar.php');
$query = "SELECT nome, contacto FROM utilizadores";
$executar_query = mysqli_query($conn, $query);
$contar = mysqli_num_rows($executar_query);
for($i=0;$i<1;$i++){
$html[$i] = "";
$html[$i] .= "<table>";
$html[$i] .= "<tr>";
$html[$i] .= "<td><b>Nome</b></td>";
$html[$i] .= "<td><b>contacto</b></td>";
$html[$i] .= "</tr>";
$html[$i] .= "</table>";
}
$i = 1;
while($ret = mysqli_fetch_array($executar_query)){
$retorno_nome = $ret['nome'];
$retorno_contacto = $ret['contacto'];
$html[$i] .= "<table>";
$html[$i] .= "<tr>";
$html[$i] .= "<td>".$retorno_nome."</td>";
$html[$i] .= "<td>".$retorno_contacto."</td>";
$html[$i] .= "</tr>";
$html[$i] .= "</table>";
$i++;
}
$arquivo = 'soudev.xlsx';
header ("Expires: Mon, 26 Jul 2100 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header ("Content-type: application/x-msexcel");
header ("Content-Disposition: attachment; filename={$arquivo}" );
header ("Content-Description: PHP Generated Data" );
for($i=0;$i<=$contar;$i++){
echo $html[$i];
}
?>
just change
$html[$i] .= "<table>";
for$html[$i] = "<table>" em ambas as tags
<table>`– djva
Yes, it will also work. But I believe my answer is correct. Just look at my explanation.
– Andrei Coelho
Including, in the
for
you did just that:$html[$i] = "";
. I just followed your line of reasoning. I think you should approve my answer. Hug.– Andrei Coelho
You can also put mine as a good doubt because so the
exportar
forxls
works perfectly and will know how to use.– djva