CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 PHP fwrite for APPEND in CSV data file

Print topic Send  topic

Author Message
justman
Posted: 10/18/2004, 6:54 PM

Hi All,

I want the code below to append two more (Customer Number and Customer File) fields in the column row of the csv file first.

Then append ( C048468145-2) values for the Customer Number field and (C048468145-2.csv ) value for the Customer File field second.

<?

// Filename
$filename = "c:\C048468145-2.csv";

// Prepare extra column header for the csv file
$cust_file = "Customer File,";

// Prepare another column header for the csv file
$cust_num = "Customer Number,";

// Open file for writing and reading
$fd = fopen ($filename, "a+")or die("Could not open file for append!");;


// Write the value of the variable $cust_file at the beginning of the first row.
fwrite ($fd, $cust_file ) or die("Could not write $cust_file to file");

// Write the value of the variable $cust_num at the beginning of the first row.

fwrite ($fd, $cust_num) or die("Could not write $cust_num to file");

//Then append ( C048468145-2) and ( C048468145-2) simultanously for each data row below the columns.

// Append the contents of the file to the variable $content
$contents = fread ($fd,filesize ($filename)) or die ("Could not read file after append or write!");

//Close file after reading
fclose ($fd);
?>

ORIGINAL DATA CONTENT BEFORE APPEND
Item,Product Number,Product,Type,Date,Time,Stock Number,Cost GST$

,822454396,Local,23-Aug,8:12 AM,822416654,7.25,,

822454396,Local,23-Aug,1:43 PM,822415333,5.36,,

DATA CONTENT AFTER APPEND
Customer Name,Customer File,Item,Product Number,Product,Type,Date,Time,Stock Number,Cost GST$

C048468145-2,C048468145-2.csv,822454396,Local,23-Aug,8:12 AM,822416654,7.25,,

C048468145-2,C048468145-2.csv,822454396,Local,23-Aug,1:43 PM,822415333,5.36,,


Thanks for your help in advance.

Justman


Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.