0

What I am trying to do is pass my database to excel. This is what I have so far:

$contents = "Nombre, Dirrecion, Telefono, Categoria, Correo\n";

$query = "SELECT datos.list, datos.addr, datos.tel, datos.cat, mail.mail FROM datos RIGHT JOIN mail ON datos.id = mail.id";

$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)){
  if(!empty($row['list'])){
    $contents.=$row['list'].",";
    $contents.=$row['addr'].",";
    $contents.=$row['tel'].",";
    $contents.=$row['cat'].",";
    $contents.=$row['mail']."\n";
  }
}
$contents = strip_tags($contents);

Header("Content-Disposition: attachment; filename='excExport".date('d-m-Y').".csv'");
print $contents;

It prints out the contents correctly, when I try to open excExport.csv I can't seem to find this file in my computer.

user3368897
  • 41
  • 1
  • 6

1 Answers1

0

Windows uses a combination of \r and \n for a new line so instead of \n use \r\n.

Example: $contents = "Nombre, Dirrecion, Telefono, Categoria, Correo \r\n";

Check out this link: \r\n , \r , \n what is the difference between them?

P.S. I'm assuming this is for windows because your using Excell, this won't work in other situations.

Community
  • 1
  • 1
Craig Lafferty
  • 771
  • 3
  • 10
  • 31