hope someone can help with this.
I am trying to create a a flatfile database which stores a line number as a unique id
Example:
1 | $Name | $Email | $Date |
2 | $Name | $Email | $Date |
3 | $Name | $Email | $Date |
4 | $Name | $Email | $Date |
and so on...
im have trouble trying to get the next save location, when an entry has been removed.
Example:
if entry 2 has been removed & the next entry is saved it is saved as
5 instead of 2.
I've tried a number of things but all fail.
i have tried doin this with a function
example:
$x =1;
function FindNextID($z)
{
$ffile = "dbfile.dat";
$fdata = file($ffile);
for ($q = 0; $q < sizeof($fdata); $q++)
{
list ($id, $name, $email, $date) = explode("|", trim($fdata[$q]));
if ($id >= $z)
{
$z = $id+1;
}
}
DoSave($z); // Take the next ID and save
}
FindNextID($x);
This code will find the next id location but does not take into account if id 2 is missing
so i tried somethin like this
$x =1;
function FindNextID($z)
{
$dosave = 1;
$ffile = "dbfile.dat";
$fdata = file($ffile);
for ($q = 0; $q < sizeof($fdata); $q++)
{
list ($id, $name, $email, $date) = explode("|", trim($fdata[$q]));
if ($id == $z)
{
$dosave = 0;
$z = $z+1;
FindNext($z);
}
}
if ($dosave)
{
DoSave($z);
}
}
FindNextID($x); // can be called from another function
this is as close as i can get .... it does save the next location but!!
after about 2 saves it does mental lol! and saves the same data over again with a new id
I know there is somethin missing but not sure what
any help would be great
thanks!!
PS .. please note i have not entered global $var as i didnt feel the need in the demo :p