Note that there are some explanatory texts on larger screens.

plurals
  1. POExport mysql to txt / xml file and download it
    primarykey
    data
    text
    <p>i have a table which shows some mysql data, every entry has a checkbox to select individual entries, now i want to be able to export those selected entries into a xml or txt file, i tried this:</p> <pre><code>&lt;?php if ($_POST['exporttxt']) { for ($i = 0; $i &lt; count($_POST['checkbox']); $i++) { $export_id = $checkbox[$i]; $sql = "SELECT * FROM table WHERE id='$export_id'"; $result = mysql_query($sql); } $output = "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n&lt;root&gt;\n"; if ($result-&gt;num_rows &gt; 0) { while ($myrow = $result-&gt;fetch_assoc()) { $output .= "\t&lt;row&gt;\n"; foreach ($myrow as $_name =&gt; $_value) { $output .= "\t\t&lt;$_name&gt;$_value&lt;/$_name&gt;\n"; } $output .= "\t&lt;/row&gt;\n"; } } $output .= "&lt;/root&gt;"; } header('content-type: text/xml'); header('content-disposition: attachment; filename=data_export.xml'); echo $output; exit; ?&gt; </code></pre> <p>But that didn't work at all, any hints ?</p> <p>I've changed the code a bit, i am now using this</p> <pre><code>&lt;?php if ($_POST['exporttxt']) { for($i=0;$i&lt;count($_POST['checkbox']);$i++){ $export_id = $checkbox[$i]; $text = mysql_query("SELECT code FROM ticket WHERE id='$export_id'"); $text = mysql_fetch_assoc($text); $text = $text["code"]; ob_end_flush(); header("Content-type: text/plain"); header("Content-disposition: attachment;filename=\"filename.txt\""); header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); header("Content-Description: File Transfer"); header("Content-Length: ".strlen($output).";\n"); echo($text); } } ?&gt; </code></pre> <p>I now get proper output on my screen, but it won't offer me to download the file ?</p>
    singulars
    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.
 

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