Re: [PHP] Export/Write rows from DBF to CSV

[email protected] (OBXer)
Newsgroups php.general
Message-ID <[email protected]>
I'm trying to adopt this piece of code for my use.  I fixed the csv_data .=
trim error.  Does anyone know how I can fix empty fields?  Everything is
dumping to a csv file but information is not matching up.  I don't know if I
can insert a space or something if field is blank?


Rahul S. Johari-2 wrote:
> 
> Ave,
> 
> I'm trying to retrieve data from a DBF database and write it to a CSV  
> file in a comma delimited format. I'm able to get the data and write  
> it to CSV, but it only writes the last row/record ... not all the  
> records. I know I don't have the correct code and I'm hoping someone  
> can help me...
> 
> _____________
> #CREATE CSV
> $date = date('mdy');
> $_file = 'CSV/TransferData_'.$date.'.csv';
> $_fp = @fopen( $_file, 'w' );
> 
> 	#SELECT DBF TO OPEN - READ ONLY
> 	$db = dbase_open("mydata.dbf", 0);
> 	#PULL UP RECORD
> 	if ($db) {
> 	  $record_numbers = dbase_numrecords($db);
> 	  for ($i = 1; $i <= $record_numbers; $i++) {
> 		$row = dbase_get_record_with_names($db, $i);
> 		
> 		#WRITE ROWS TO VARIABLE
> 		$_csv_data = trim($row['PHONE']).",".trim($row['DATE']).","."\n";  
> <-- THIS is where my problem is! This only writes the last row!!
> 	  }
> 	}
> 
> #WRITE TO CSV	
> @fwrite( $_fp, $_csv_data );
> @fclose( $_fp );
> 
> 

-- 
View this message in context: http://old.nabble.com/Export-Write-rows-from-DBF-to-CSV-tp22496924p27646825.html
Sent from the PHP - General mailing list archive at Nabble.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.