1

below is my CSV file.

enter image description here

and this is my viewer in web

enter image description here

My question is, how can i edit the highlighted one in HTML Table i want to change the "Star Apple, 4 , 2" into "Pineapple, 7, 3"? by the way i use also codeigniter here and i don't have database. All i need to do is to edit the existing data in HTML Table and automatically update it in CSV file. Thank you for your help.

bebebe
  • 339
  • 2
  • 7
  • 20
  • What is this button doing? **Export CSV File**? Is it for exporting the modified csv? – jogesh_pi Mar 21 '14 at 04:40
  • 1
    i will edit my question. That 'EXPORT CSV FILE' is nothing. – bebebe Mar 21 '14 at 06:06
  • The logic that you can use is, First collect CSV data into array then make html input fields based on that array. Then again collect the modified data into array and export it with new CSV file. Got IT? – jogesh_pi Mar 21 '14 at 06:23
  • 2
    Yes, i got it. In fact i've already done it and that's the use of the `Export CSV File` button that i have removed a while ago but is their other way that when I edit the data it will automatically update in CSV file without downloading another CSV file? – bebebe Mar 21 '14 at 06:53

1 Answers1

0

I would do:

on client side:

  1. "onchange" event on every input in every row
  2. AJAX to the server with: index of a row and whole row imploded to a string (csv format)
  3. If response status isn't okay, undo changes with JS.

on server side:

  1. open a file with file()
  2. replace an array line
  3. write new file
  4. answer if file is written correctly

This idea will serve you asynchronous method of editing csv file. Of course you must block editing during execution of AJAX request. If you have big csv files this link can help you fasten the server process:

Overwrite Line in File with PHP

Community
  • 1
  • 1
avall
  • 2,025
  • 2
  • 16
  • 28