RE: FW: write to file, difficulty inputting data

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

 



On Wed, June 1, 2005 6:41 am, mayo said:
> I need to write to file. After getting a customer's order I'm sending a
> file to a distribution company. The company wants all the information in
> a preset format which they will then parse.
>
> The problem comes when I try to put in multiple orders. In other words
> how does one use
>

$file = fopen("/path/to/file", "a+");

> while($row = mysql_fetch_array( $result ))
> {

fputs($file, "whatever you want");

> }

fclose($file);

>
> inside a variable -- or put the results into said variable
>
> The process I've set up is:
> 1. get data from session variables, $_POST and a database
> (this orderID, itemsOrdered and customerAddress, etc...)
> 2. put it into a variable called $fileContent
> 3. then write $fileContent to $file

Actually you should *STILL* put all the crap in a database.

Then, say, once a week, pull all the stuff out of the database, send it to
the guy in whatever format they want, and mark the records you sent (and
ONLY the records you successfully sent) as "done"

Separate the capturing and recording of the data from the sending it off
to somebody in whatever format they want.

One, because they will probably change their format on you, or go out of
business, or whatever, and then you'd have to change the guts of your form
processing.  Not good.

Two, because when it comes time to work out what happened to "missing"
orders/data, you've got a database trail of what you did.

Three, because by separating the order-taking from the order-fulfillment
(or, in your case, sending it off to somebody else to deal with) you are
dividing your problem into two smaller, more managable chunks.  Always a
good idea.

> Example below:
>
> $thisOrder= sprintf("%12d",$orderID[0]);
> ...
>
> $fileContent=
>
> $thisOrder .
> $_POST["shippingMethodName"] .
> $a .
> $b .
> $c
>
> ; // end of $fileContent
>
>
> Now, I would like to put my orders into $fileContent. How does one place
> the output of
>
> while($row = mysql_fetch_array( $result ))
> {
> }
>
> into $fileContent?
>
> Thx.
>
> Mayo
>
>
>
>
>
> -----Original Message-----
> From: Richard Lynch [mailto:ceo@xxxxxxxxx]
> Sent: Wednesday, June 01, 2005 1:13 AM
> To: mayo
> Cc: php-general@xxxxxxxxxxxxx
> Subject: Re:  FW: write to file, difficulty inputting data
>
> On Tue, May 31, 2005 5:32 pm, mayo said:
>>     if (!$handle = fopen($filename, 'w')) {
>
> This will WIPE OUT the existing file, and write a *NEW* file, from 0,
> starting from scratch.
>
> So you'll never have anything but the LAST item.
>
> You could use "a+" to append to the end of the file...
>
> But you *SHOULD* be using a database to avoid concurrency issues.
>
> You're going to have a MUCH better application if you store your data in
> the database, and it's EASIER than messing with a file.
>
> Only use a file if a database is absolutely forbidden by outside
> factors.
> Like badly-design homework assignments.  Or not-very-smart
> pointy-haired-bosses.
>
> --
> Like Music?
> http://l-i-e.com/artists.htm
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux