>> I have a php website connecting to mysql database.
>> How can i have a user export his database through
>> the webpage to csv format?
>> I would like the user to have a button he can press
>> that would pop up a
>> "save as" screen so he can save his database.

The PHP code to do this would look something like this:

 // -- Do not send any HTML before this point -- //

 header("Content-type: application/vnd.ms-excel");
 header('Content-Disposition: attachment; filename="myfile.xls"');
 header("Content-Transfer-Encoding: binary");

 $r1 = // -- do query here -- //;
 $nf = mysql_num_fields($r1);
 for ($i=0; $i<$nf; $i++) {
  $x = mysql_field_name($r1,$i);
  echo '"' . str_replace('"','""',htmlspecialchars($x)) . '"\t';
 }
 echo "\n";
 while ($a1 = mysql_fetch_array($r1)) {
  for ($i=0; $i<$nf; $i++) {
   $x = $a1[$i];
   echo '"' . str_replace('"','""',htmlspecialchars($x)) . '"\t';
  }
  echo "\n";
 }

Hope this helps.

 - seb


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to