I know I know, a database would be the better idea with what I want to do, but I don’t want the hassle of dealing with a database and learning stuff.
I have a CSV that has something similar to
TestUser,2010/07/27 13:26:25,2010/07/27 13:26:29,0.0011,0.0006,0.06
TestUser,2010/07/27 14:22:12,2010/07/27 14:22:24,0.0033,0.0027,0.27
TestUser,2010/07/27 14:22:41,2010/07/27 14:22:53,0.0033,0.0028,0.28
TestUser,2010/07/27 14:25:26,2010/07/27 14:25:33,0.0019,0.0015,0.30
the 2nd column is what I am using as a UID (unique ID), so it will never be the same in the CSV. The PHP code I use to write to the csv is:
$myFile = "data.csv";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = $_POST["Name"].",".$_POST["DateStart"].",".$_POST["DateStop"].",".$_POST["TotalHours"].",".$_POST["Hours"].",".$_POST["Pay"]."\n";
fwrite($fh, $stringData);
fclose($fh);
What would need to be done to have it so if someone with the same DateStart (the UID) runs the PHP, it will overwrite whatever has that same UID. Basically I am thinking it would probably have to go through an file array with each line and then when it reaches a line that has the same UID, it would instead intercept what was POSTed and not what it has.
I am not sure if that is the best way of going about what I want.
While I completely agree with ircmaxell (learn to use a database), you still deserve a proper response to the question.
I do believe you would have to read line by line and do the comparison. No, it’s not very efficient, but your setup doesn’t really allow for efficiency.
“I am not sure if that is the best way of going about what I want.”
As ircmaxell suggested, using a database would be incredibly simple. mysql is free and is a piece of cake to pick up. Something as simple as this will be able to be hammered out in a couple hours tops.