I am using the code below to export from MySQL to Excel. The problem is that some of the time, I get extra (empty) lines (rows) in my spread sheet with no apparent common reason. It's almost as if there were two '\n' being written at the end.
Any ideas?
[blue]
// Write the column names
for($i = 0; $i < $fieldcounts; $i++)
{
$fieldtype = mysql_fetch_field($result, $i);
echo "$fieldtype->name";
if ($i < ($fieldcounts-1))
echo "\t";
else
echo "\n";
}
// Write the rows
while ($myrow = mysql_fetch_array($result))
{
for($i = 0; $i < $fieldcounts; $i++)
{
$fieldname = mysql_field_name($result, $i);
if ($i < ($fieldcounts-1))
echo $myrow[$fieldname] . "\t";
else
echo $myrow[$fieldname] . "\n";
}
}
[/blue]
Any ideas?
[blue]
// Write the column names
for($i = 0; $i < $fieldcounts; $i++)
{
$fieldtype = mysql_fetch_field($result, $i);
echo "$fieldtype->name";
if ($i < ($fieldcounts-1))
echo "\t";
else
echo "\n";
}
// Write the rows
while ($myrow = mysql_fetch_array($result))
{
for($i = 0; $i < $fieldcounts; $i++)
{
$fieldname = mysql_field_name($result, $i);
if ($i < ($fieldcounts-1))
echo $myrow[$fieldname] . "\t";
else
echo $myrow[$fieldname] . "\n";
}
}
[/blue]