write to file, difficulty inputting data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm writing customer orders into a file. I'm 
 
1. getting data from session variables and a database,
2. putting it into a variable called $fileContent
3. then touch($filename);
4. then writing $fileContent to $filename - the code is at the bottom
 
The test versions of this have all gone well.
 
The file must contain the data in a preset format. All the data is on
one line (no line breaks) and each field has a preset limit, The file is
FTPed and the data parsed.
 
So far so good. It works with one customer order
 
Now when I want to write multiple customer orders it doesn't work?
Abbreviated code is below
 
// CODE FOR MULTIPLE ORDERS
 
while($row = mysql_fetch_array( $result ))
{
 
$theItemID=$row["orderedItems.itemID"];
$theItemPrice=$row["itemPrice"];
$theItemQty=$row["itemQty"];
 
$thisItemID= sprintf("% 6d",$theItemID);
$thisItemPrice= sprintf("%7.2f",$theItemPrice);
$thisItemQty= sprintf("% 7d",$theItemQty);
 
$moreContent=
 
"\n" .
"20" .
$thisOrder .
 
$thisItemID .
 
$thisItemPrice .
 
$thisItemQty . "\n";
 
                        }
//END CODE
 
// CODE BELOW IS FOR WRITE TO FILE
 
// Make sure the file exists and is writable first.
if (is_writable($filename)) {
 
    // Open $filename in write mode.
 
    if (!$handle = fopen($filename, 'w')) {
         echo "Cannot open file ($filename)";
         exit;
    }
 
    // Write $fileContent to opened file.
    if (fwrite($handle, $fileContent) === FALSE) {
        echo "Cannot write to file ($filename)";
        exit;
    }
 
    fclose($handle);

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux