title: SQL result as txt.file by php
body: <p>I have a php file, which transform my sql query in a php output. Everything works fine. But now i need a output as txt.file and my code does not work.</p>
  
  <p>Here the query:</p>
  
  <pre><code>&lt;?php
  $pdo = new PDO('mysql:host=localhost;dbname=DB', 'USER', 'PW');
  
  $result = ("SELECT o.order_id AS Bestellnummer, o.customer_id AS Kundennummer, o.order_status_id AS Bestellstatus, op.quantity AS Anzahl, op.model AS Pharmacode, op.name AS Bezeichnung, p.location AS Lieferant, o.shipping_company AS Firma, o.shipping_firstname AS Vorname, o.shipping_lastname AS Nachname, o.shipping_address_1 AS Lieferadresse, o.shipping_postcode AS PLZ, o.shipping_city AS Ort
  FROM oc_order o
  INNER JOIN oc_order_product op
  ON o.order_id = op.order_id
  INNER JOIN oc_product p
  ON op.product_id = p.product_id
  WHERE o.order_status_id = 1 AND p.location = 1
  ORDER BY o.order_id, op.model");
  
  
  
  echo "&lt;table border='0'&gt;
  &lt;tr&gt;
  &lt;th&gt;Best.Nr&lt;/th&gt;
  &lt;th&gt;Kd.Nr&lt;/th&gt;
  &lt;th&gt;Status&lt;/th&gt;
  &lt;th&gt;Anz.&lt;/th&gt;
  &lt;th&gt;Pharmacode&lt;/th&gt;
  &lt;th&gt;Bezeichnung&lt;/th&gt;
  &lt;th&gt;Lieferant&lt;/th&gt;
  &lt;th&gt;Firma&lt;/th&gt;
  &lt;th&gt;Vorname&lt;/th&gt;
  &lt;th&gt;Nachname&lt;/th&gt;
  &lt;th&gt;Adresse&lt;/th&gt;
  &lt;th&gt;PLZ&lt;/th&gt;
  &lt;th&gt;Ort&lt;/th&gt;
  &lt;/tr&gt;";
  
  foreach ($pdo-&gt;query($result) as $row) {
  
    echo "&lt;tr&gt;";
    echo "&lt;td&gt;" . $row['Bestellnummer'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Kundennummer'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Bestellstatus'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Anzahl'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Pharmacode'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Bezeichnung'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Lieferant'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Firma'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Vorname'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Nachname'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Adresse'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['PLZ'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Ort'] . "&lt;/td&gt;";
    echo "&lt;/tr&gt;";
    }
  echo "&lt;/table&gt;";
  
  
  mysql_close($con);
  ?&gt;
  </code></pre>
  
  <p>I need the endcode for a output in txt or csv. I suppose that the initial code (SELECT...) has no clear output string to connect at a new code for the output.</p>