The name is the database if "Lastname, Firstname" - so when I export to excel the firstname goes into the second field. I have tried using an explode to no avail.
PHP Code:
include("../connectdb.php");
$XML = "name,phone,department\n";
$file ="directory-". date("Y-m-d"). ".csv";
$query = "SELECT * FROM directory_national WHERE title!='Room' AND city='toronto' OR city='ottawa' ORDER BY name";
$result = mysql_query($query);
while($rows = mysql_fetch_array($result)) {
$name = $rows["name"];
$phone = $rows['phone'];
$department = $rows['department'];
Also though, is there a way that the data can cme out clean without me having to do a search and replace for the unique character, that is, enclose the name with its comma?
That worked thanks, but there is an error in your code: a comma is missing
D'oh!
Also though, is there a way that the data can cme out clean without me having to do a search and replace for the unique character, that is, enclose the name with its comma?
Yea, take a look at my second part (which I have have edited after you saw my initial post).
If you enclose the entire string in quotation marks, that should give you the whole string in one cell (assuming the string doensn't contain quotes).
Sorry ssytems - I misunderstood what you had said. I thought you were on the same reply as OctoberWind.
Ok so looking at your suggestion it makes a lot of sense but I am sorry I dont know how to do what you ask. 1. get dat from db I can do that. 2. Build an array - have no clue how or what to array.
... CSV is a point coma format, and not a coma format^^
CSV is an acronym for "Coma" Separated Values. Technically it can be any string separated values, it can be tabs, pipes, double pipes, superstring variable, etc.
Your code
Code:
$query = "SELECT * FROM directory_national WHERE title!='Room' AND city='toronto' OR city='ottawa' ORDER BY name";
$result = mysql_query($query);
is # 1: Get the data
for #2: Build the array, below mysql_fetch_array already made it an array for you and is actually an associated one
Code:
while($rows = mysql_fetch_array($result)) {
// append to csv file
}
Bookmarks