Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Edit row in flat file

Status
Not open for further replies.

buzzt

Programmer
Oct 17, 2002
171
CA
I am able to retrieve the row I want (from a flat file). Now I would like to be able to edit and/ or delete that row only without affecting those before or after. Is there a way?

Here's how I am getting the row info ($ed is the id for that row which is posted to the page by clicking a link with the id for that row in it.)

Code:
   $file  = fopen("ans.txt","a+");
   $count = file("ans.txt");
   $num   = count($count);

   for ($i=0; $i<$num; $i++)
   {
     $edrow = explode("|", $count[$i]);
     if ($edrow[0]==$ed)
     {
     	$edid   = $edrow[0];
     	$edqrow = $edrow[1];
     	$edarow = $edrow[2];
     }
     
   }
 
That's a good point... in the solution I provided you would need to use a separate function (unset()) to do a deletion, whereas with array_splice you can just modify arguments.

My commentary on overly complex is really only based on the fact that array_splice works on offsets instead of keys, and in my personal experience I have an easier time working with keys.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top