output query php CSV in a column

0

I have the following code:

$Name = 'NOMINA-'.$mes.'-'.$dia.'-'.$ano.'.csv';


$rpedidos = "SELECT total,
         cuenta FROM nomina";
          $reg = $conexion->query($rpedidos);
          while( $reg_File = $reg->fetch_array() )
          {
               $ceros="000";
     $ttpago=number_format($reg_File["total"],2);
    $ctaBco=$reg_File["cuenta"];
     $tt="".$ctaBco."".$ceros."".$ttpago."";
    $shtml = $tt."\n";

          }

//$shtml=$excel;  
//$shtml=$shtml."</table>";  
header("Content-Description: File Transfer");  
header("Content-Type: application/force-download");  
header('Content-Disposition: attachment; filename='.$Name.''); 
echo $shtml; 

It generates me perfectly, CSV but it divides me the totals in two columns and I only need it in one, some guide.

Thank you.

    
asked by Alexander Quiroz 18.01.2017 в 00:11
source

1 answer

0

Please note that the CSV are files where the values are separated by:

  • Comma ( , )
  • O! semicolon ( ; ) where the regional configuration uses the comma as a decimal separator, example: Argentina, Brazil, Spain, etc.

For any of these cases, the way to escape the separator is to print the value in double quotes ( " ).

Solution:

$tt = '"'.$ctaBco.$ceros.$ttpago.'"';

PS: Double quotes are escaped with double quotes, for example:

$valor = 'valor "con comillas"';
// En el CSV
"valor ""con comillas"""
    
answered by 18.01.2017 / 14:46
source