Código PHP:
   define(db_host, "localhost");
define(db_user, "root");
define(db_pass, "");
define(db_link, mysql_connect(db_host,db_user,db_pass));
define(db_name, "productiva_contactos");
mysql_select_db(db_name);
 
$categoria = $_GET['categoria'];
$subcategoria = $_GET['subcategoria'];
$especialidad = $_GET['especialidad'];
$IDDEPARTAMENTO = $_GET['IDDEPARTAMENTO'];
$IDSERVICIO = $_GET['IDSERVICIO'];
$ciudad = $_GET['ciudad'];
 
/********************************************
Write the query, call it, and find the number of fields
/********************************************/
$select =("SELECT DISTINCT E.NOMBRE, S.DIRECCION, S.CIUDAD, C.NOMBRE, D.DESCRIPCION 
      FROM empresa E, sede S, contacto C, servicio_empresa P, tiposervicio T, departamento D
      WHERE S.IDEMPRESA = E.IDEMPRESA
      AND  S.IdSede = C.IdSede
      AND  S.IdSede = P.IdSede
      AND  S.IdEmpresa=P.IdEmpresa
      AND  P.IdServicio = T.IdServicio
      AND S.IDSEDE = C.IDCONTACTO
      AND C.IDDEPARTAMENTO = D.IDDEPARTAMENTO
      AND S.del ='1'
      AND E.del ='1'
      AND P.del ='1'
      AND C.del ='1' 
      AND ( E.CATEGORIA = '$categoria'
      OR E.SUBCATEGORIA = '$subcategoria'
      OR E.ESPECIALIDAD = '$especialidad'
      OR T.IDSERVICIO = '$IDSERVICIO'
      OR S.CIUDAD = '$ciudad'
      OR C.IDDEPARTAMENTO = '$IDDEPARTAMENTO')");
      
$export = mysql_query($select);
$count = mysql_num_fields($export);
 
/********************************************
Extract field names and write them to the $header
variable
/********************************************/
for ($i = 0; $i < $count; $i++) {
$header .= mysql_field_name($export, $i)."\t";
}
/********************************************
Extract all data, format it, and assign to the $data
variable
/********************************************/
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);
/********************************************
Set the default message for zero records
/********************************************/
if ($data == "") {
$data = "\n(0) Records Found!\n";
}
/********************************************
Set the automatic downloadn section
/********************************************/
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=consulta.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data"; 
    si alguno de ustedes puede ayudarme le agradecería
chao
ing_aprendiz
 
