I've had a good scour through these forums and across google for some how to's and it's starting to confuse me a little so I thought I'd ask at the place where it's at...
As the Subject says, I want to export a bunch of stuff to a .CSV file. To be exact, I want to export the Name and Address of each customer in my MySQL database so I can do a mailmerge in OpenOffice and print out all the envelopes required.
Details of table (and the fields I've chosen to print) are as such:
Code: Select all
Table: Clients
Chosen Fields: name_first, name_last, add_street, add_city, add_state, add_pcodeCode: Select all
$connection = mysql_connect($dbhost, $dbusername, $dbpassword);
$dir = "DESC";
mysql_select_db($dbname);
$sql = "SELECT * FROM clients ORDER BY name_last ASC";
$content = mysql_query($sql);
$Xcontent = mysql_fetch_array($content);
$cShowMax = mysql_num_rows($content);
for ($y=1; $y<=$cShowMax; $y++)
{
//Get the info from the database and smack it in variables for user later
$id = $Xcontent["id"];
$name_first = $Xcontent["name_first"];
$name_last = $Xcontent["name_last"];
$phone_home = $Xcontent["phone_home"];
$add_street = $Xcontent["add_street"];
$add_city = $Xcontent["add_city"];
$add_state = $Xcontent["add_state"];
$add_pcode = $Xcontent["add_pcode"];
$bday_day = $Xcontent["bday_day"];
$bday_month = $Xcontent["bday_month"];
$bday_year = $Xcontent["bday_year"];
if ($add_street != "") //if they have a street address (for postage)
{
//add this data to the csv file
name_first, name_last, add_street, add_city, add_state, add_pcode
}
$Xcontent = mysql_fetch_array($content);
//mysql_free_result($content);
}Any pointers would really be appreciated. I saw PHP has the ability to read a csv file and perhaps even write one, but it didn't make a lot of sense to me. I'm not the most advanced programmer by any means.
Thanks again, I really appreciate any help,
Rob
(EDIT: I should note that addresses sometimes have / and , and ' in them. An example is this:
Code: Select all
name_first: John
name_last: Smith
add_street: Shop 2/25 Corner of Mc'Farlane, Davidson Street
add_city: Michealton
add_state: Queensland
add_pcode: 4568