Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

export to excel in php

$queryexport = ("
SELECT username,password,fullname FROM ecustomer_users
WHERE fk_customer='".$fk_customer."'
");

$row = mysql_fetch_assoc($queryexport);

$result = mysql_query($queryexport);
$header = '';

for ($i = 0; $i < $count; $i++){
   $header .= mysql_field_name($result, $i)."	";
   }

while($row = mysql_fetch_row($result)){
   $line = '';
   foreach($row as $value){
          if(!isset($value) || $value == ""){
                 $value = "	";
          }else{
                 $value = str_replace('"', '""', $value);
                 $value = '"' . $value . '"' . "	";
                 }
          $line .= $value;
          }
   $data .= trim($line)."
";
   $data = str_replace("
", "", $data);

if ($data == "") {
   $data = "
no matching records found
";
   }
}
header("Content-type: application/vnd.ms-excel; name='excel'");
header("Content-Disposition: attachment; filename=exportfile.xls");
header("Pragma: no-cache");
header("Expires: 0");

// output data
echo $header."
".$data;

mysql_close($conn);`
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #export #excel #php
ADD COMMENT
Topic
Name
9+1 =