Jump to content

Recommended Posts

New-to-php guy here...

I'm dropping fields from a table into a flat file. But each row from the table is not a single line in the flat file.

Standard flat file:

Field1Field2Field3Field4Field5Field6

 

What I need:

Field1Field2Field3

Field1Field4Field5

Field1Field6

 

etc...

 

I can't find the command to specify when a new row should be started.

I am extremely new to php. I have searched everywhere but probably am not using the correct lingo.

 

Thanks for any help.

Andrew

Link to comment
https://forums.phpfreaks.com/topic/103446-flat-file-command-question/
Share on other sites

Where in the sample of code below would I insert the \r\n to get, say, "batchnum" on the second line?

(This is the code for another flat file that somebody else wrote. I am just inserting my info and learning as I go.)

 

function cleanRow( &$row ){

if( is_null($row['custname']) || empty($row['custname']) ){

for( $j=0; $j<23; $j++ ){

$row['custname'] .= ' ';

}

}

if( is_null($row['headrectype']) || empty($row['headrectype']) ){

for( $j=0; $j<1; $j++ ){

$row['headrectype'] .= ' ';

}

}

if( is_null($row['filler29']) || empty($row['filler29']) ){

for( $j=0; $j<29; $j++ ){

$row['filler29'] .= ' ';

}

}

if( is_null($row['batchnum']) || empty($row['batchnum']) ){

for( $j=0; $j<50; $j++ ){

$row['batchnum'] .= ' ';

}

}

Here?

 

for( $i=0; $i<$rowcount; $i++ ){

cleanRow( $table[$i] );

$line = sprintf( '%s%s%s%s%s%s%s%s%s%s%s%s%s%s%c%c', $table[$i]['partnumber'], $table[$i]['AltPartNum'], $table[$i]['Grouping'],$table[$i]['description'],

$table[$i]['sourcecode'], $table[$i]['categorycode'],$table[$i]['unitofmeasure'], $table[$i]['PackageUnitQTY'],$table[$i]['orderquantity'], $table[$i]['MovementCode'],

$table[$i]['supercededto'], $table[$i]['cost'], $table[$i]['retail'],$table[$i]['UPC'], 13, 10 );

fputs( $out, $line );

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.