how do I pass a database to excel using php? -
what trying pass database excel. have far:
$contents = "nombre, dirrecion, telefono, categoria, correo\n"; $query = "select datos.list, datos.addr, datos.tel, datos.cat, mail.mail 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 contents correctly, when try open excexport.csv can't seem find file in computer.
windows uses combination of \r
, \n
new line instead of \n
use \r\n
.
example: $contents = "nombre, dirrecion, telefono, categoria, correo \r\n
";
check out link: \r\n , \r , \n difference between them?
p.s. i'm assuming windows because using excell, won't work in other situations.
Comments
Post a Comment