[thelist] PHP writing to a csv file

Martin Kuplens-Ewart martin at takingitglobal.org
Mon Apr 8 11:06:00 CDT 2002


> I am having problems writing to a csv file does anyone know of a good
tutorial

I just did it by doing it...
...erm, what kind of problem are you having?

If it's an issue with data spilling over into different columns
[probably caused by commata in the data itself], may I suggest using tab
delimiting?

Gets really easy with that.
Eg:

FieldName1	FieldName2	FieldName3
<?
$q = "SELECT * FROM $db.$table";
$qe = mysql_query($q);
while($qr = mysql_fetch_array($qe))
{
?>
<?=$qr[Field1]?>	<?=$qr[Field2]?>	<?=$qr[Field3]?>

<?
}
?>

Replace the field name stuff with the names of fields [if you want a key
included], and the query result field names too...

-m





More information about the thelist mailing list