Output to excel
Posted: Tue Mar 24, 2009 9:45 am
Does anyone know of an easy way to output a mysql query result to a spreadhseet.
Currently I am using a bit of code:
that simply creates a .csv file which can be opened. However when you open the file all the lines of data from the database are bunched up in one cell on the left hand side.
Is there any way the data can be seperated into different cells and also is there a way of adding a field name to the top of the columns?
Currently I am using a bit of code:
Code: Select all
<?php
$mysqli = mysqli_connect("localhost", "my_user", "my_pass", "my_db");
$sql = "SELECT * FROM salesperson INTO OUTFILE 'test.csv';
$res = mysqli_query($mysqli, $sql)
or die(mysqli_error($mysqli));
?>Is there any way the data can be seperated into different cells and also is there a way of adding a field name to the top of the columns?