I have looked at the information regarding array sorting on the PHP.net site, but I'm not sure that's what I want to or can even do in this case.
I have a flat file(.txt) where each line is a separate piece of data like below:
Name^Date^Time^Code
Currently, the data MUST be entered in DATE order, i.e. 7/2/04 then 7/3/04 then 7/6/04. If the dates are entered out of order, the whole thing goes to hell rather quickly.
Obviously, that's a problem.
So, I want to be able to locate the place where the data should be entered into the file.
File:
Joe^7/1/04^10^1
Joe^7/2/04^14^5
Joe^7/6/04^8^7
Entry = Joe^7/3/04^16^2
The Entry should be placed after 7/2/04 and before 7/6/04.
Currently, this is where I'm at:
$abs_Date = the Entry Date and $fields[1] = the File Date
Thoughts? How do I proceed?
TIA
DreamerZ
I have a flat file(.txt) where each line is a separate piece of data like below:
Name^Date^Time^Code
Currently, the data MUST be entered in DATE order, i.e. 7/2/04 then 7/3/04 then 7/6/04. If the dates are entered out of order, the whole thing goes to hell rather quickly.
Obviously, that's a problem.
So, I want to be able to locate the place where the data should be entered into the file.
File:
Joe^7/1/04^10^1
Joe^7/2/04^14^5
Joe^7/6/04^8^7
Entry = Joe^7/3/04^16^2
The Entry should be placed after 7/2/04 and before 7/6/04.
Currently, this is where I'm at:
Code:
if(!($fp_opFile=@fopen("$abs_Operator.txt","r")))
{
echo "<script> alert('File Error. Contact Support');
window.location='bstAbsence.phtml'</script>";
}
else
{
$tmp_fp = fopen("tempfile.txt","a");
while (@!feof($fp_opFile))
{
$opInfo = @fgets($fp_opFile);
$fields = explode("^",$opInfo);
if (trim($abs_OLDInfo) != trim($opInfo))
{
if (strtotime($fields[1]) < strtotime($abs_Date))
{
fwrite($tmp_fp, $opInfo);
}
else
{
fwrite($tmp_fp,$abs_Info);
fwrite($tmp_fp, "\n");
}
}
}
fclose($tmp_fp);
fclose($fp_opFile);
//rename("tempfile.txt", "$abs_Operator.txt");
}
Thoughts? How do I proceed?
TIA
DreamerZ