I have been trying to save my database as an excel file. After much research of looking at other codes and loads of trial and errors I was able to find what I needed- below is the code to do just that!

I have it saved as a stand-alone php file, with a link from another page that calls it. The page will pop=up an alert to save hte file, and viola!

Code:
<?php


define(db_host, "");
define(db_user, "");
define(db_pass, "");
define(db_link, mysql_connect(db_host,db_user,db_pass));
define(db_name, "");
mysql_select_db(db_name);

$select = "SELECT * FROM name";                
$export = mysql_query($select);
$fields = mysql_num_fields($export);

for ($i = 0; $i < $fields; $i++) {
    $header .= mysql_field_name($export, $i) . "\t";
} 

while($row = mysql_fetch_row($export)) {
    $line = '';
    foreach($row as $value) {                                            
        if ((!isset($value)) OR ($value == "")) {
            $value = "\t";
        } else {
            $value = str_replace('"', '""', $value);
            $value = '"' . $value . '"' . "\t";
        }
        $line .= $value;
    }
    $data .= trim($line)."\n";
}
$data = str_replace("\r","",$data); 

if ($data == "") {
    $data = "\n(0) Records Found!\n";                        
} 
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename=NameOfFileHere.xls');
print "$header\n$data";  


?>