Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Array - modify values
Old 04-24-2005, 05:56 PM Array - modify values
Novice Talker

Posts: 9
Trades: 0
Greetings,

Still learning - still fussing with my flatfiles

I have gone around in a variety of circles testing options.
time for help!!!!!

I want to give the user the option to change data in their (f'file) dbase entry.

$fh = fopen("$datafile","r+");
while(!feof($fh))
{ $line = fgets($fh);
$row = explode("\t",$line);
if ($row[0] == $name) // $name from login form

this gives me the row I am after
row[14] is the value I want to change.

I think to do something like:
$new_line = $row;
unset($row);
fwrite($fh,$new_line);

BUT it do no woik

am I heading in the right direction
where to from here
OR....

is there a simpler routine to modify a specific 'cell' value

I know it is pretty basic stuff but - until I get a good feel of the environment and its variables - "I'll be back..."

Any suggestions much appreciated.

thanks - arfa
arfa is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-25-2005, 04:36 AM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
You need to change $row[14] to the desired value, and then use the implode() function to collapse the array back to a string - this reverses the effect of explode() except that entry numbe 14 is changed.

PHP Code:
$row[14] = "New Value";
$new_line implode("\t",$row);
fwrite($fh,$new_line); 
I'm unsure about the fwrite part - I don't use flatfiles much at all so I'm not sure if this will write to the correct line or just replace the whole file with that one line....
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 04-25-2005, 10:38 AM
Novice Talker

Posts: 9
Trades: 0
Hi Oberon,

I think what I have failed to appreciate is that fwrite needs to write the *whole* file - not just the line I am editing.
At least this is my current approach.

Many thanks for your suggestion.
I will set the final solution - as and when it arrives

arfa
arfa is offline
Reply With Quote
View Public Profile
 
Old 04-25-2005, 10:58 AM
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
I have always found it difficult to edit 1 line from a file then write it back. Instead I too get the file as an array, edit the element and write the whole thing back.

Its ok when the file is small but problems will no doubt emerge when your dealing with large files.

Ibbo
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Linux user #349545 :
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCf
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Old 04-25-2005, 04:40 PM
Novice Talker

Posts: 9
Trades: 0
Cheers Ibbo,

Yes - an array (vert. entries) of arrays (horiz. cells) seems to be the way. I am making progress and am learning bits along the way.

> dealing with large files.
At the moment I am around 500 entries per file max so not so big.
My eventual move seems to SQL - but I am still getting the PHP environment into my head.

thanks - arfa
arfa is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Array - modify values
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.14997 seconds with 12 queries