Page 1 of 1

Exporting data into a text file

Posted: Sun Jul 24, 2005 6:01 pm
by summitweb
Hello:

It's been a long time since I had the need to create a dataset based on a specified data file format.

I'm designing a website for a mortgage broker. On his site he wants to have the ability for people to complete a loan application. No problem there, I'm using PHP to process the form.

He has a third party software which keeps track of the loan and prepares all the necessary documents for closing. He needs to import that data from the loan app on the website into this third party software.

The software uses a data file format from Fannie Mae. I have their data dictionary along with the data file format information showing the position of each field, length of each field, etc.

How do I go about creating this dataset from the information entered via the online loan application? What tools are being used in order to achieve this?

I hope someone can steer me in the right direction to accomplish this.

Thank you for any help.

Posted: Mon Jul 25, 2005 8:45 am
by mickd
my guess is, if i understood correctly youll need:

fopen() http://au3.php.net/manual/en/function.fopen.php
fwrite() http://au3.php.net/manual/en/function.fwrite.php
fclose() http://au3.php.net/manual/en/function.fclose.php

fileopen, filewrite and fileclose.

Posted: Thu Jul 28, 2005 4:35 pm
by sulen
This is the code to export data to a csv file .......... you can develop some ideas of this

Code: Select all

<?php 
define(db_host, "localhost"); 
define(db_user, "db_username"); 
define(db_pass, "db_pwd"); 
define(db_link, mysql_connect(db_host,db_user,db_pass)); 
define(db_name, "db_name"); 
mysql_select_db(db_name); 

$select = "your query";                 
$export = mysql_query($select); 
$fields = mysql_num_fields($export); 

for ($j = 0; $j < $fields; $j++) { 
    $header .= mysql_field_name($export, $j) . "\t"; 
} 
while($row = mysql_fetch_row($export)) { 
    $line = ''; 
    foreach($row as $value) {                                             
        if ((!isset($value)) OR ($value == "")) { 
            $value = "\t"; 
        } else { 
            $value = str_replace('"', '""', $value); 
            $value = '"' . $value . '"' . "\t"; 
        } 
        $line .= $value; 
    } 
    $data .= trim($line)."\n"; 
} 
$data = str_replace("\r","",$data); 

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

header("Content-type: application/octet-stream"); 
header("Content-Disposition: attachment; filename=filename.csv"); 
header("Pragma: no-cache"); 
header("Expires: 0"); 
print "$header\n$data"; 

?>
Hope this gives you some direction.