Difficulty setting a "changing" variable.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vcarter
Forum Newbie
Posts: 14
Joined: Sun Jun 21, 2009 3:02 pm

Difficulty setting a "changing" variable.

Post by vcarter »

Hi all -

Here is my current block of code:

Code: Select all

do { 
$customerData=fgets($handleReadCA);
$temp=explode("\t",$customerData);
$invoiceNum=$temp[0];
 if($temp[0]=="+") { $temp[0] = $invoiceNum; } 
 else { $invoiceNum = $temp[0]; } 
$value=implode("\t",$temp); 
fputs($handleWriteCA, $value);
} while(!feof($handleReadCA));
Basically, I'm taking a text file which is full of customer order information, with the first field being the invoice number. In the text file, if a customer has ordered more than one item, the subsequent order information only has a "+" for the invoice number, rather than the invoice number itself. So I'm trying to step through the data, and if a "+" is found, then use the previous (correct, or stored) invoice number.

However, I can't seem to get this to happen - all my data is then written with the "+" and not the actual invoice number.

Any help would be TREMENDOUSLY appreciated. I hope I've explained this clearly.

(edited: took out code comments)

Virginia
vcarter
Forum Newbie
Posts: 14
Joined: Sun Jun 21, 2009 3:02 pm

Re: Difficulty setting a "changing" variable.

Post by vcarter »

Nevermind! I think I got this working, finally.

Code: Select all

$customerData=fgets($handleReadCA);
$temp=explode("\t",$customerData);
$invoiceNum=$temp[0];
$value=implode("\t",$temp); 
fputs($handleWriteCA, $value);
do { 
$customerData=fgets($handleReadCA);
$temp=explode("\t",$customerData);
//exit(print_r($invoiceNum));
 if($temp[0]=="+") { $temp[0] = $invoiceNum; }
 else { $invoiceNum = $temp[0]; }
$value=implode("\t",$temp); 
fputs($handleWriteCA, $value);
} while(!feof($handleReadCA));
This appears to work.
Post Reply