Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

deleting row in csv file

 
   Database Forums (Home) -> PHP RSS
Next:  English Query still available in SQL Server 2005?  
Author Message
nescio

External


Since: Oct 06, 2005
Posts: 5



(Msg. 1) Posted: Mon Oct 24, 2005 10:55 am
Post subject: deleting row in csv file
Archived from groups: alt>php (more info?)

hello,

i have made a script to read/add and update rows in an csv file.
it works fine.

but when i change an existing row i want the original row to disapear.
now i get two rows: the original one en the changed one.

so my question is: how can i delete a row in a csv file?


thanks

 >> Stay informed about: deleting row in csv file 
Back to top
Login to vote
Stefan Rybacki

External


Since: Jun 18, 2005
Posts: 204



(Msg. 2) Posted: Mon Oct 24, 2005 10:55 am
Post subject: Re: deleting row in csv file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

nescio wrote:
> hello,
>
> i have made a script to read/add and update rows in an csv file.
> it works fine.
>
> but when i change an existing row i want the original row to disapear.
> now i get two rows: the original one en the changed one.
>
> so my question is: how can i delete a row in a csv file?
>

open source file, create a temporary file. Copy any line to the temporary file but the one
you want to delete. Afterwards, move the temporary files to the original source file.

Regards
Stefan

>
> thanks
>
>

 >> Stay informed about: deleting row in csv file 
Back to top
Login to vote
Nicolas Verhaeghe - White

External


Since: Oct 21, 2005
Posts: 1



(Msg. 3) Posted: Mon Oct 24, 2005 10:55 am
Post subject: Re: deleting row in csv file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

>> hello,
>>
>> i have made a script to read/add and update rows in an csv file.
>> it works fine.
>>
>> but when i change an existing row i want the original row to disapear.
>> now i get two rows: the original one en the changed one.
>>
>> so my question is: how can i delete a row in a csv file?
>>
>
> open source file, create a temporary file. Copy any line to the temporary
> file but the one you want to delete. Afterwards, move the temporary files
> to the original source file.
>
> Regards
> Stefan

Tricky if more than one user at a time... I would have the CSV file imported
into MySQL (or whatever database server you use), then once the data is
manipulated, export to the CSV. Or export to CSV on demand, or on schedule.
 >> Stay informed about: deleting row in csv file 
Back to top
Login to vote
Stefan Rybacki

External


Since: Jun 18, 2005
Posts: 204



(Msg. 4) Posted: Mon Oct 24, 2005 3:55 pm
Post subject: Re: deleting row in csv file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

JDS wrote:
> On Mon, 24 Oct 2005 16:06:48 +0200, nescio wrote:
>
>
>>so my question is: how can i delete a row in a csv file?
>
>
> The question is, how are you reading, updating, and rewriting to the file?
>
> I recommend using file() to read the file into an array.
>
> Then update the value of the array
>
> Then write the value of the array back out to the file, overwriting the
> old file in the process. Use fopen() and fwrite().
>

Well this is what I would do in any other programming language (except java). But since
php has memory restrictions (mostly 8MB) I wouldn't recommend such a way, without knowing
the worst case (max size of the file). Just to mention. Wink

Regards
Stefan
 >> Stay informed about: deleting row in csv file 
Back to top
Login to vote
nescio

External


Since: Oct 24, 2005
Posts: 1



(Msg. 5) Posted: Mon Oct 24, 2005 3:55 pm
Post subject: Re: deleting row in csv file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

> I recommend using file() to read the file into an array.
>
> Then update the value of the array
>
> Then write the value of the array back out to the file, overwriting the
> old file in the process. Use fopen() and fwrite().


it is a small file, and they don't use a database, and they have only a few
users.

so this looks a very effective solution.

thanks for your help
 >> Stay informed about: deleting row in csv file 
Back to top
Login to vote
steve

External


Since: Sep 02, 2005
Posts: 5



(Msg. 6) Posted: Mon Oct 24, 2005 3:55 pm
Post subject: Re: deleting row in csv file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

| But since php has memory restrictions (mostly 8MB)

uhhh...try 2GB.
 >> Stay informed about: deleting row in csv file 
Back to top
Login to vote
Stefan Rybacki

External


Since: Jun 18, 2005
Posts: 204



(Msg. 7) Posted: Mon Oct 24, 2005 4:55 pm
Post subject: Re: deleting row in csv file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

steve wrote:
> | But since php has memory restrictions (mostly 8MB)
>
> uhhh...try 2GB.
>
Tell this your provider! If you have your own server with not that much concurrent scripts
running, setting the memore restrictions to a higher level is fine but not always possible .

Regards
Stefan
 >> Stay informed about: deleting row in csv file 
Back to top
Login to vote
steve

External


Since: Sep 02, 2005
Posts: 5



(Msg. 8) Posted: Mon Oct 24, 2005 4:55 pm
Post subject: Re: deleting row in csv file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

| > | But since php has memory restrictions (mostly 8MB)
| >
| > uhhh...try 2GB.
| >
| Tell this your provider! If you have your own server with not that much
concurrent scripts
| running, setting the memore restrictions to a higher level is fine but not
always possible .

what restrictions my provider may employ have *no* bearing on php's string
memory limit which *is* 2gb and not "mostly" 8mb. your statement is
inaccurate. i was speaking to the inaccuracy of your claim...if you meant
"limits of most providers", you should have said so. if you meant "server
restrictions", you should have said so.
 >> Stay informed about: deleting row in csv file 
Back to top
Login to vote
Ted Ferenc

External


Since: Mar 01, 2005
Posts: 1



(Msg. 9) Posted: Tue Oct 25, 2005 5:55 am
Post subject: Re: deleting row in csv file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

The old fashioned way was to have a 'deleted' flag in the CSV file, instead
of removing a line simply set the deleted flag, i.e. one field, when you
parse the CSV file look for the deleted flag, if set the line is 'deleted'
so ignore it.

Once in a while go through the CSV file and physically remove all rows
flagged as deleted, if your CSV file is getting too big.

Now the next problem is what if 2 people are writing to the file at the
'same time'?

--

Ted Ferenc
This address used is maintained only for newsgroup posting.
Mail sent there may not be read by me for several days.
"nescio" wrote in message

> hello,
>
> i have made a script to read/add and update rows in an csv file.
> it works fine.
>
> but when i change an existing row i want the original row to disapear.
> now i get two rows: the original one en the changed one.
>
> so my question is: how can i delete a row in a csv file?
>
>
> thanks
>
>
 >> Stay informed about: deleting row in csv file 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Deleting from table using AJAX - HI every one I have problem for deleting data from table using ajax this code to insert user data and show the data in table using ajax it work fine but for another code that use to delete data and show the date in same table it dose not work and this..

how do you open a file with quote marks in the file name o.. -

want to get content of one php file in another php file - i have one php file having content Contents of ex1.php file <body> <?php $content = "c://webserver/www/abc.php"; $handle = fopen($content, "r"); echo fread($handle,filesize($content)); ?> </body> this is reading abc...

getting the name of the PHP file - Hi! I am a PHP beginner, and I don't know my way around. Let's say I have a file named as "file.php". Is there a special variable that already includes the file name, or should I just manually code it into the script; i.e. $filename = "...

File selection? - I'm running some php scripts locally (Windoze XP) to operate on local files and, at least partly because I can't seem to access the parameters via argv[] or get it to print out in my DOS box, it seems sensible to run it via a web page (I'm running..
   Database Forums (Home) -> PHP All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]