Saving data to flatfile
Posted: Wed Sep 13, 2006 5:27 pm
hi all
hope someone can help with this as im totally head mashed & need a new perspective
Basically i have creating a php pm system that works great
Now in the admin CP i have an option to clean data which includes pms
all data is stored in flatfiles as i dont have sql and this script is designed for others like me.
all messages are stored in files like this for example:
pmd-Username.dat
inside this each pm is stored like this line by line:
pmcode|date|from|subject|message|status
the status part tells us if the message is 'read' or 'new'
i have got my script to seperate 'read' messages & 'new' messages
so i now have three possible options for the clean option in the admin CP
1. Clean - Read Messages
2. Clean - New Messages
3. Clean - All Messages
option 3 is done - no probs!!
the problem is option 1 or 2 - I know if i get one of them then the other is gonna be the same.
this is the code im having trouble with
this code works and is the building block for what i need help with, sorry if im goin on lol its hard to explain
now i have my 'new' & 'read' data, as this code is ''cleanold'' i only want to save $ndata
this is where im lost as i need to make sure i save the right messages back to the right users
note the following code
i have already saved the username in $file[1] which = 'username.dat'
i keep looking at it and i see it lookin at me but i just can get it
any help would be much appreciated
I hope you find this easy to read
ta
-::BlAzE::-
hope someone can help with this as im totally head mashed & need a new perspective
Basically i have creating a php pm system that works great
Now in the admin CP i have an option to clean data which includes pms
all data is stored in flatfiles as i dont have sql and this script is designed for others like me.
all messages are stored in files like this for example:
pmd-Username.dat
inside this each pm is stored like this line by line:
pmcode|date|from|subject|message|status
the status part tells us if the message is 'read' or 'new'
i have got my script to seperate 'read' messages & 'new' messages
so i now have three possible options for the clean option in the admin CP
1. Clean - Read Messages
2. Clean - New Messages
3. Clean - All Messages
option 3 is done - no probs!!
the problem is option 1 or 2 - I know if i get one of them then the other is gonna be the same.
this is the code im having trouble with
Code: Select all
if ($pm == "cleanold")
{
$dir = opendir("$pmdir"); $c = 0; //assign & open the dir for stored user pms
while ($file = readdir($dir)) // loop through to collect all files
{
$c = $c + 1;
if ($c < 3) { continue; }
$file = explode("-", $file);
if ($file[0] == "pmd")
{
$pmfile = "$pmdir/pmd-{$file[1]}";
$hnd = file($pmfile);
for ($x = 0; $x < sizeof($hnd); $x++) // Open all files that start with pmd
{
list($id, $smdate, $sfrom, $ssub, $smess, $status) = explode('|', trim($hnd[$x]));
$status = trim($status); // Make sure we are not processing black data
if ($status == "new") // Start seperation 'new' else 'read'
{
$ndata[] = $file[1]."|".$id."|".$smdate."|".$sfrom."|".$ssub."|".$smess."|".$status;
}
else
{
$rdata[] = $file[1]."|".$id."|".$smdate."|".$sfrom."|".$ssub."|".$smess."|".$status;
}
}
}
}
include ("done.htm"); exit();
}now i have my 'new' & 'read' data, as this code is ''cleanold'' i only want to save $ndata
this is where im lost as i need to make sure i save the right messages back to the right users
note the following code
Code: Select all
$ndata[] = $file[1]."|".$id."|".$smdate."|".$sfrom."|".$ssub."|".$smess."|".$status;
}
else
{
$rdata[] = $file[1]."|".$id."|".$smdate."|".$sfrom."|".$ssub."|".$smess."|".$status;i keep looking at it and i see it lookin at me but i just can get it
any help would be much appreciated
I hope you find this easy to read
ta
-::BlAzE::-