Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- CSV output
- Steven Paul
October 19, 2006, 11:22 pm
rate this thread
I need to write the output of an SQL query as comma-separated values.
So I wrote this, which is almost right:
while($row = mysql_fetch_array($rs, MYSQL_ASSOC))
$rows = $row;
foreach( $rows as $key => $value)
foreach ($rows as $row)
foreach( $row as $key => $value)
It first writes a header row, then all the data rows below it. The only
problem is the trailing comma on each line. Is there some clever way of
knowing when I'm on the last element, and so not add the last comma?
If it's not already blindingly obvious, I'm new to PHP ;-)