fordyh Posted April 29, 2008 Share Posted April 29, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/103446-flat-file-command-question/ Share on other sites More sharing options...
wildteen88 Posted April 29, 2008 Share Posted April 29, 2008 Use \r\n or \r or \n \r\n is for Windows. \n is for *nix \r is for Macs note these characters only work in double quotes. PHP will treat these characters as-is if you use single quotes. Quote Link to comment https://forums.phpfreaks.com/topic/103446-flat-file-command-question/#findComment-529724 Share on other sites More sharing options...
fordyh Posted April 29, 2008 Author Share Posted April 29, 2008 Thank you very much. I figured it would be something simple. I'll be picking up a php book this weekend. Thanks again. Andrew Quote Link to comment https://forums.phpfreaks.com/topic/103446-flat-file-command-question/#findComment-529747 Share on other sites More sharing options...
fordyh Posted April 29, 2008 Author Share Posted April 29, 2008 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'] .= ' '; } } Quote Link to comment https://forums.phpfreaks.com/topic/103446-flat-file-command-question/#findComment-529775 Share on other sites More sharing options...
wildteen88 Posted April 30, 2008 Share Posted April 30, 2008 That function is not used to insert data into your flat file. It is used to format the data to be inserted into to your flat file. You'll want to find the code which adds the data to the flat file. Quote Link to comment https://forums.phpfreaks.com/topic/103446-flat-file-command-question/#findComment-530498 Share on other sites More sharing options...
fordyh Posted May 1, 2008 Author Share Posted May 1, 2008 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 ); Quote Link to comment https://forums.phpfreaks.com/topic/103446-flat-file-command-question/#findComment-531055 Share on other sites More sharing options...
wildteen88 Posted May 1, 2008 Share Posted May 1, 2008 Change: fputs( $out, $line ); to fputs( $out, "$line\n"); Quote Link to comment https://forums.phpfreaks.com/topic/103446-flat-file-command-question/#findComment-531285 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.