Â
<?phpÂ
$DB_Server = “localhost”;Â Â Â
$DB_Username = “put your user name here”;Â Â Â
$DB_Password = “put your password here”;Â Â Â
$DB_DBName = “put your database name here”;Â Â Â
$DB_TBLName = “put your table name here”;Â Â Â
 Â
$savename = date(“YmjHis”);Â // excel file name
$Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password) or die(“Couldn’t connect.”);Â Â Â
mysql_query(“Set Names ‘utf-8′”);
$file_type = “vnd.ms-excel”;Â Â Â
$file_ending = “xls”;
header(“Content-Type: application/$file_type;charset=utf-8”);
header(“Content-Disposition: attachment; filename=”.$savename.”.$file_ending”);Â Â Â
//header(“Pragma: no-cache”);Â Â Â Â Â Â
 Â
$now_date = date(“Y-m-j H:i:s”);Â Â Â Â
$title = “User Email”;Â Â Â Â
 Â
$sql = “SELECT entity_id, email from $DB_TBLName WHERE entity_id >’0′ AND entity_id<10001”;Â Â Â Â //export entity_id from 1 to 1000
$ALT_Db = @mysql_select_db($DB_DBName, $Connect) or die(“Couldn’t select database”);Â Â Â
$result = @mysql_query($sql,$Connect) or die(mysql_error());Â
 Â
echo(“$title\n”);Â Â Â Â
$sep = “\t”;Â Â Â Â
for ($i = 0; $i < mysql_num_fields($result); $i++) {
   echo mysql_field_name($result,$i) . “\t”;   Â
}Â Â Â Â
print(“\n”);Â Â Â Â
$i = 0;Â Â Â Â
while($row = mysql_fetch_row($result)) {Â Â Â Â
   $schema_insert = “”;
   for($j=0; $j<mysql_num_fields($result);$j++) {   Â
       if(!isset($row[$j]))   Â
           $schema_insert .= “NULL”.$sep;   Â
       elseif ($row[$j] != “”)   Â
           $schema_insert .= “$row[$j]”.$sep;
       else   Â
           $schema_insert .= “”.$sep;   Â
   }   Â
   $schema_insert = str_replace($sep.”$”, “”, $schema_insert);   Â
   $schema_insert .= “\t”;   Â
   print(trim($schema_insert));   Â
   print “\n”;   Â
   $i++;   Â
}Â Â Â Â
return (true);Â
?>