Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL to Excel

Status
Not open for further replies.

buzzt

Programmer
Joined
Oct 17, 2002
Messages
171
Location
CA
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 &quot;$fieldtype->name&quot;;
if ($i < ($fieldcounts-1))
echo &quot;\t&quot;;
else
echo &quot;\n&quot;;
}
// 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] . &quot;\t&quot;;

else
echo $myrow[$fieldname] . &quot;\n&quot;;
}
}
[/blue]
 
I think that's it. But I can't see the newlines. When I re-wrote the content for one of the lines manually, the break in the spread sheet went away. How do I get rid of all of these in the column if I can't even see them?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top