when exporting data from a query in php mysql the csv file contains html

0

At the moment of generating the CSV file it only contains HTML, I checked my query and there are no null values, or anything like that, I leave you a photo of the code and I thank you in advance for your time.

Greetings brothers!

CSV output

CeDis   Unidades    Tipo Combustible    Proveedor   Num. Factura    Ticket-Folio    Nombre del chofer   Kilometraje Fecha consumo   Litros  Precio Unitario Subtotal    Rendimiento
<br />                                              
<font size='1'><table class='xdebug-error xe-warning' dir='ltr' border='1' cellspacing='0' cellpadding='1'>                                             
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Warning: fputcsv() expects parameter 1 to be resource   object given in C:\wamp64\www\Fuel\demo.php on line <i>54</i></th></tr>                                            
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>                                             
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>                                              
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0005</td><td bgcolor='#eeeeec' align='right'>248560</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp64\www\Fuel\demo.php' bgcolor='#eeeeec'>...\demo.php<b>:</b>0</td></tr>                                                
<tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.0033</td><td bgcolor='#eeeeec' align='right'>269560</td><td bgcolor='#eeeeec'><a href='http://www.php.net/function.fputcsv' target='_new'>fputcsv</a>                                             
(  )</td><td title='C:\wamp64\www\Fuel\demo.php' bgcolor='#eeeeec'>...\demo.php<b>:</b>54</td></tr>                                             
</table></font>                                             
<br />                                              
<font size='1'><table class='xdebug-error xe-warning' dir='ltr' border='1' cellspacing='0' cellpadding='1'>                                             
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Warning: fputcsv() expects parameter 1 to be resource   object given in C:\wamp64\www\Fuel\demo.php on line <i>54</i></th></tr>                                            
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>                                             
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>                                              
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0005</td><td bgcolor='#eeeeec' align='right'>248560</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp64\www\Fuel\demo.php' bgcolor='#eeeeec'>...\demo.php<b>:</b>0</td></tr>                                                
<tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.0370</td><td bgcolor='#eeeeec' align='right'>270640</td><td bgcolor='#eeeeec'><a href='http://www.php.net/function.fputcsv' target='_new'>fputcsv</a>                                             
(  )</td><td title='C:\wamp64\www\Fuel\demo.php' bgcolor='#eeeeec'>...\demo.php<b>:</b>54</td></tr>                                             

  

Warning: fputcsv () expects parameter 1 to be resource object given in C: \ wamp64 \ www \ Fuel \ demo.php on line 54

Code

<?php
 require('php/config.php');

 $fecha1 = $_POST['fecha1'];
 $fecha2 = $_POST['fecha2'];

 header('Content-Type:text/csv; charset-latin1');
 header('Content-Disposition:attachment; filename="reporte_combustible.csv"');

 $salida = fopen('php://output','w');

 // encabezados

 fputcsv($salida,
   array(
     'CeDis','Unidades','Tipo Combustible',
     'Proveedor','Num. Factura','Ticket-Folio',
     'Nombre del chofer','Kilometraje','Fecha consumo',
     'Litros','Precio Unitario','Subtotal','Rendimiento'
   )
 );

 $query ="SELECT 
 a.Name as Cedis,
 b.Name as Unidades,
 d.Name as Combustible,
 c.Name as Proveedor,
 e.Invoice as Factura,
 e.Ticket as TicketFolio,
 e.Driver as Conductor,
 e.Mileage as Kilometraje,
 e.Intake as FechaConsumo,
 e.Litters as Litros,
 e.UnitCost as PrecioUnitario,
 e.Subtotal as Subtotal,
 e.Efficiency as Rendimiento
 FROM branch as a
  INNER JOIN asset as b ON a.Id = b.Branch_Id
  INNER JOIN supplier as c ON  a.Id = c.Branch_Id
  INNER JOIN supply as d ON c.Id = d.Supplier_Id
  INNER JOIN data as e ON d.Id = e.Supply_Id AND b.Id = e.Asset_Id
 WHERE e.Intake BETWEEN '$fecha1' AND '$fecha2'";

 $resultado = mysqli_query($link,$query);

 while($fila = mysqli_fetch_assoc($resultado))
 {
         fputcsv($resultado, array(
         $fila['Cedis'],
         $fila['Unidades'],
         $fila['Combustible'],
         $fila['Proveedor'],
         $fila['Factura'],
         $fila['TicketFolio'],
         $fila['Conductor'],
         $fila['Kilometraje'],
         $fila['FechaConsumo'],
         $fila['Litros'],
         $fila['PrecioUnitario'],
         $fila['Subtotal'],
         $fila['Rendimiento']));

 }


?>

[! [enter the description of the image here] [2]] [2]

    
asked by Ed Brennenburg 04.10.2018 в 19:01
source

0 answers