Jump to content

Recommended Posts

i found a solution of this, but the data output is all in one line, i have  use the "\n", but everything still printed out in one line, just wondering, i wanna the record to be printed out in many lines based on different ID.


for ($i = 0; $i < $fields; $i++) {
    $header .= mysql_field_name($export, $i) . "|";
}

while($row = mysql_fetch_row($export)) {
    $line = '';
    foreach($row as $value) {
        if ((!isset($value)) OR ($value == "")) {
            $value = "|";
        } else {
            //$value = str_replace('|', '', $value);
            $value = "|".$value."|";
        }
        $line .= $value;
    }
    //$data .= trim($line). "\n";
    $data .= $line."\n";
}
//$data = str_replace("\r","",$data);

if ($data == "") {
    $data = "\n(0) Records Found!\n";
}

header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=extraction.txt");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
if you just want a simple text file, you could just loop through the records you want and build a string formatted the way you want and then the code below is an example of how to create the actual text file

[code]
$fh = fopen('FILE_PATH', 'w') or die("ERROR: can't open file for writing");
fwrite($fh, $NEW_FORMATTED_STRING);
fclose($fh);
[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.