Note that there are some explanatory texts on larger screens.

plurals
  1. POexport Mysql table data to CSV with PHP on header without html code
    primarykey
    data
    text
    <p>I am trying to export some some data from Mysql with PHP to .CSV file </p> <p>The issue is script export .CSV file but in the .CSV file before tabels there are HTML code </p> <p><em><strong>Here you have the script</em></strong> <pre><code>// Get all fields names in table "mytablename" in database "pendejas". $fields = mysql_list_fields(pendejas,$table_name); // Count the table fields and put the value into $columns. $columns = mysql_num_fields($fields); // Put the name of all fields to $out. for ($i = 0; $i &lt; $columns; $i++) { $l=mysql_field_name($fields, $i); $out .= '"'.$l.'",'; } $out .="\n"; // Add all values in the table to $out. while ($l = mysql_fetch_array($result)) { for ($i = 0; $i &lt; $columns; $i++) { $out .='"'.$l["$i"].'",'; } $out .="\n"; } // Open file export.csv. $f = fopen ('export.csv','w'); // Put all values from $out to export.csv. fputs($f, $out); fclose($f); header('Content-type: application/csv'); header('Content-Disposition: attachment; filename=$table_name.csv'); readfile('$table_name.csv'); ?&gt; </code></pre> <p>How can i export ONLY Mysql Table contains ?</p> <p>appreciate your help </p> <p>EDIT : SOLVED ! </p> <p><em><strong>Here you have script</em></strong></p> <pre><code>&lt;?php $result = mysql_query("SELECT name, time FROM $table_name"); ob_end_clean(); if ($result) { while ($row = mysql_fetch_array($result)) { $pasajeros .= $row["name"] . ";". $row["time"]. "\r\n"; //note the comma here } } $filename = "pasajeros_" . date("Y-m-d_H-i"); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header("Content-disposition: filename=" . $table_name . ".csv"); print $pasajeros; exit(); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload