Ver Mensaje Individual
  #7 (permalink)  
Antiguo 07/06/2012, 20:15
Avatar de Nemutagk
Nemutagk
Colaborador
 
Fecha de Ingreso: marzo-2004
Ubicación: México
Mensajes: 2.633
Antigüedad: 20 años, 1 mes
Puntos: 406
Respuesta: exportar consulta de base de datos a archivo txt abierto

te estas complicando demasiado, lo que pretendes es realmente sencillo...

Para escribir el archivo...
Código PHP:
Ver original
  1. <?php
  2.  
  3. $sql = 'SELECT * FROM mitabla';
  4. $query = mysql_query($sql,$conexion) or die (mysql_error());
  5.  
  6. $archivo = 'archivo.txt';
  7.  
  8. $handler = fopen($archivo,'a');
  9. while($row = mysql_fetch_assoc($query)) {
  10.      fwrite($handler,$row['mi_campo']);
  11. }
  12. fclose($handler);

y para visualizarlo en el navegador solo es necesario hace un include('archivo.txt'); o si deseas forzar la descarga...
Código PHP:
Ver original
  1. <?php
  2. $archivo = 'archivo.txt';
  3. header('Content-Type: application/force-download');
  4. header('Content-Disposition: attachment; filename='.$archivo);
  5. header('Content-Transfer-Encoding: binary');
  6. header('Content-Length: '.filesize($archivo));
  7.  
  8. include($archivo);
__________________
Listo?, tendría que tener 60 puntos menos de IQ para considerarme listo!!!
-- Sheldon Cooper
http://twitter.com/nemutagk
PD: No contestaré temas vía mensaje personal =)