<?php
global $coupon;
$sfp = fopen('test.csv','w'); //instead of test.cvs we should have item $description.cvs
// $dfp = fopen('edited.cvs','w');
$row=fgetcsv($sfp,10000,",","");
$tetris=off; //this var will be kept like this until we get a match on coupon
$i=1;
while (tetris==off){
if ($row[i,2]=="unsold"){ // acts only when the row has the unsold tag, otherwise moves on
$coupon=$row[i,1]$; // gets the coupon number from the first column
str_replace("unsold","sold",$row[i,1]); // changes the unsold into sold so next time it'll be skipped
fwrite($sfp,$row); // writes the actual new row to the file
$tetris=on; // changes tetris to on which will break out the while loop so program ends.
}
else {$i++} // if the if fails, it means the coupon was sold and we need to move down to next row
}
fclose($sfp);
?>