<?

$link = mysql_connect("localhost","ricardoo_forms","123XY");
mysql_select_db("ricardoo_forms",$link);
 
$sql = "SELECT * FROM Profesional ORDER BY ID DESC";
 
$r = mysql_query( $sql ) or trigger_error( mysql_error($conn), E_USER_ERROR );
$return = '';
if( mysql_num_rows($r)>0){
    $return .= '<table border=1>';
    $cols = 0;
    while($rs = mysql_fetch_row($r)){
        $return .= '<tr>';
        if($cols==0){
            $cols = sizeof($rs);
            $cols_names = array();
            for($i=0; $i<$cols; $i++){
                $col_name = mysql_field_name($r,$i);
                $return .= '<th>'.$col_name.'</th>';
                $cols_names[$i] = $col_name;
            }
            $return .= '</tr><tr>';
        }
        for($i=0; $i<$cols; $i++){
            $return .= '<td>'.$rs[$i].'</td>';
        }
        $return .= '</tr>';
    }
    $return .= '</table>';
    mysql_free_result($r);
}

header("Content-type: application/vnd-ms-excel; charset=iso-8859-1");
header("Content-Disposition: attachment; filename=PROFESIONAL-".date('d-m-Y-G-i').".xls");
echo $return; 

?>