You could do something like:

$result = mysql_query($query) or die(mysql_error());  // don't display
errors on production machines
$first = TRUE;
while ($line = mysql_fetch_array($result))
{
  if ($first)
   {     
     foreach ($line as $key => $value)
     { 
       if ($first)
       { fwrite($file_handle, $key); $first = FALSE; }
       else
       { fwrite($file_handle, ", $key"); }
     }
     fwrite ($file_handle, "\n");
   }
   $number1 = TRUE;
   foreach ($line as $value)
   {
     if ($number1) 
     { fwrite ($file_hande, $value); $number1 = FALSE; } 
     else 
     { fwiret ($file_hande, ", {$value}"; };
   }
   fwrite ($file_handle, "\n");
}

That is pseudo code though.  (i.e. I don't have time to test it and
debug it and make it nice and neat and readable and conform to your
specifications -- but it should give you a good idea of how to start).

-Dan

On Fri, 2003-10-10 at 17:38, Cesar Aracena wrote:
> Hi all,
> 
> Does anybody knows how to make a CSV (comma separated values) file with
> PHP based on results fetched from MySQL? I need it to import it with
> Microsoft Outlook Express.
> 
> Thanks in advanced,
> 
> Cesar Aracena
> www.icaam.com.ar

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to