TECNOLOBO

No recuerdas tu codigo?
Se te olvido como se hace?

Aqui podras guardar lo que necesiten
Y cuando sea necesesario

Creado por julian gomez
iiiiii

Crear Un CSV con PHP



Descripcion

es muy importante los header para poder que se des

php


//conection: 
$link = mysqli_connect("myhost","myuser","mypassw","mybd") or die("Error " . mysqli_error($link)); 
 
$Name = 'Reporte_UltimaCuotaPaga.csv';
$FileName = "./$Name";
$Datos = 'NOMBRE;APELLIDO;TELEFONO;CIUDAD';
$Datos .= "\r\n";
 
//Descarga el archivo desde el navegador
header('Expires: 0');
header('Cache-control: private');
header('Content-Type: application/x-octet-stream'); // Archivo de Excel
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Description: File Transfer');
header('Last-Modified: '.date('D, d M Y H:i:s'));
header('Content-Disposition: attachment; filename="'.$Name.'"');
header("Content-Transfer-Encoding: binary");
 
/**1.  consultar sap_maestro_cartera_v3 **/
$sSQL = "SELECT 
         nombre,
         apellido,
         telefono,
         ciudad                     
 FROM datos_personales
       ";
$RsSql = $link->mysqli_query($sSQL);
 
while($oRow = mysql_fecth_object($RsSql) ){
    $Datos .= "$oRow->nombre;$oRow->apellido;$oRow->telefono;$oRow->ciudad;   ";
    $Datos .= "\r\n"; 
 
}#end while
 
echo $Datos;