0

I try to describe my complete situation...

I read a csv file using php function. I developed a php class that represent an entry of the file. So, I have a php array that contains all my entries. When I read all entries of the file, I use a php function to visualize these into a table. For the table I use jQuery tableSorter.

Now, the user can edit some rows of this table (for this I wrote some javascript functions). At this point I need to save (on the csv file) every modified table rows. Is there a simple way to make this?

Need I to modify the php array? Is possibile to modify a php variable by javascript code? Sorry but I'm new about this.

Practical examples are welcome.

6
  • You could create an AJAX file that communicates with PHP. jQuery has an AJAX function built-in. You can then GET or POST what needs to be modified to your PHP file. Once modified you could do a page refresh. I'm not too familiar with TableSorter. Commented Apr 16, 2014 at 10:29
  • First of all let me understand the scenario, are you reading a csv file then displaying it to the user or you are using DB? Commented Apr 16, 2014 at 10:30
  • Why you always read a csv file why not storing its value in DB, and then let the user edit what ever they want store them in db and create new CSV file for the user when he asked for the same Commented Apr 16, 2014 at 10:31
  • @RohitKumarChoudhary A DB may add unnecessary overhead Commented Apr 16, 2014 at 10:34
  • So let me know how will handle the concurrent read and write operation in that CSV file Commented Apr 16, 2014 at 10:36

1 Answer 1

0

No, you're not modifying the PHP Array. There are several ways to handle your request. You could use the input fields in your table to make a POST request and save the changes to your CSV file.

The more Javascript-ish way could be an AJAX Request which is fired on change of each field. Your Server / PHP-Code is accepting that request and writes only the data of that field.

In both cases you should know how to handle POST requests / forms in PHP. Submitting a form by POST generates a new PHP array, accessible as $_POST.

Practical examples are depending on the expected behavior. Using forms will reload the page on submitting. Using AJAX not. But the usage of AJAX (XMLHTTPRequest if you want to read some documentation) is a little tricky if you're new to Javascript

Link about XMLHTTPRequest (AJAX) http://www.w3schools.com/xml/xml_http.asp

Link about Form handling: http://www.w3schools.com/php/php_forms.asp

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.