it's funny you recommended that, because right after I posted I looked up php.net's str_replace and figured out how to work with it effectively.
What I have now works 99%...and in case anyone else needs to know how the final product looked, here goes:
// create connection
$connection = mysql_connect("localhost","user","pass")
or die("Couldn't make connection.");
// select database
$db = mysql_select_db("db", $connection)
or die("Couldn't select database.");
// create SQL statement
$sql = "select distinctrow yadda, yadda2, yadda3, yadda4, UNIX_TIMESTAMP(date) AS date FROM table WHERE yadda = '$requiredyadda'";
// execute SQL query and get result
$sql_result = mysql_query($sql,$connection)
or die("Couldn't execute query.");
if (!$sql_result) {
echo "<P>Couldn't get item!";
} else {
// open file and begin writing after initial data written from earlier in script (not shown)
$csv = fopen("/path/to/file.csv", "a");
//now take results and prepare them for writing
while($row = mysql_fetch_array($sql_result))
{
$yadda = $row["yadda"];
$yadda2 = $row["yadda2"];
$yadda3 = $row["yadda3"];
// replace all commas in this field with spaces
$yadda4 = str_replace(","," ",$row["yadda4"]);
// replace any null date values which will return 12/31/1969 with N/A
$date_st = date("m/d/Y",$row["date"]);
if($date_st == "12/31/1969") $date_st = "N/A";
// now write all this mess to a file
fwrite($csv,"\n$yadda,$yadda2,$yadda3,$yadda4,$date_st\r\n");
}
fclose($csv);
The before part not shown takes all the field names and dumps them to the same file that all this data writes to. I can show you guys that part too if you're interested. After the fclose, I move on to taking the file and emailing it as an attachment to a user who was specified in the previous form page.
So basically this is my operation:
user -> yadda,email entered into a form -> submits, loads page2.php -> page2.php runs the query process and email's the report that is written to a .csv file as an attachment.
The end result is basically a csv file that has headers (field names of the table) and the data that they requested in a comma deliminated file.
Not very sexy, but it works. If anyone else was needing a similar product, I can email you the script I wrote with comments. It's the least I can do for all the help you guys have given me.