Exporting data into a text file

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
summitweb
Forum Commoner
Posts: 27
Joined: Thu Jun 30, 2005 4:28 am
Location: Atlanta, Georgia

Exporting data into a text file

Post 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.
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post 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.
User avatar
sulen
Forum Commoner
Posts: 79
Joined: Wed Jul 09, 2003 4:55 pm
Location: los angeles
Contact:

Post 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.
Post Reply