Applying a function to MySQL export to .txt
<p>I'm exporting some data from MySQL which can be selected through checkboxes on a page to a .txt file.</p>

<p>Now I have a function to "black out" middle digits of the numbers from MySQL, this function is working on my page, there it looks like this:</p>

<pre><code>&lt;?php
$sql="SELECT * FROM table";
$result=mysql_query($sql);

// Count table rows
$count=mysql_num_rows($result);

?&gt;

&lt;?php function blankit($word) {
    return substr($word, 0,2). str_repeat("X",strlen($word)-4) . substr($word, strlen($word)-2,strlen($word));
} 
?&gt;

&lt;?php while($rows=mysql_fetch_array($result, MYSQL_ASSOC)) {
$code = ($rows['used'] == '') ? blankit($rows['code']) : $rows['code']; ?&gt;
&lt;tr class="first"&gt;
&lt;td class="tc"&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;&lt;? echo $rows['id']; ?&gt;&lt;/font&gt;&lt;/td&gt;
&lt;td class="tc"&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;&lt;? echo $code; ?&gt;&lt;/font&gt;&lt;/td&gt;

&lt;td&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;&lt;? echo $rows['date']; ?&gt;&lt;/font&gt;&lt;/td&gt;
&lt;td class="tc"&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;&lt;? echo $rows['ip']; ?&gt;&lt;/font&gt;&lt;/td&gt;
&lt;td class="tc"&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;&lt;? echo $setusedpscde; ?&gt;&lt;/font&gt;&lt;/td&gt;
&lt;td class="tc"&gt;&lt;input name="checkbox[]" type="checkbox" class="checkbox" id="checkbox[]" value="&lt;? echo $rows['id']; ?&gt;"&gt;&lt;/td&gt; 


&lt;/tr&gt;
&lt;?php
}
?&gt;
</code></pre>

<p>Now I want to apply this same function (blankit) when I export to the .txt file, my export code:</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 table WHERE id='$export_id'");
$text2 = mysql_fetch_assoc($text);
$text3 = $text2["code"];
$filename = "export";
$filedate = date("Y-m-d");
$fileext = ".txt";
$fileall = $filename.$filedate.$fileext;

 ob_end_clean();
    header("Content-Type: application/octet-stream");
header("Content-disposition: attachment;filename=\"$fileall\"");
   header("Content-Type: application/force-download");

    header("Content-Type: application/download");
    header("Content-Description: File Transfer");
    header("Content-Length: ".strlen($output).";\n");



echo chunk_split($text3, 16, "\n");

}
}



?&gt;
</code></pre>

<p>I tried changing</p>

<pre><code>$text3 = $text2["code"];
</code></pre>

<p>to</p>

<pre><code>$text3 = ($text2['used'] == '') ? blankit($text2['code']) : $text2['code'];
</code></pre>

<p>But this X'ed out all the middle digits of every number, even if used was not =''</p>

<p>What do I have to change here ?</p>
