I have a HTML page. Clicking on one link within the page runs a php function which adds a HTML table to the page (implemented with AJAX, php function is in a separate php file).
Now, I have a button on the page which is supposed to run another php function which should pick up the data from the table and do something with it. I don’t know how to get the data from the table because:
- I don’t know how to reference (get) a HTML element through php.
- My php function is in a separate file.
What if I put everything from the table in POST or GET arguments? Is there a way to reference the table and iterate its rows and get the data that way? Thanks.
This is not a job for PHP, you should use Javascript to capture the table contents and then manipulate them whatever way you would like. If on the other hand the table contents never change then you can just put them into your PHP function.
You can pull the values of the table by first setting an ID for the table like so:
Then you can call the values from the table using JavaScript:
This will put all of the cells into an array. Then you can put them into variables.
Then you can put it into an AJAX Request and send it to your PHP function to be processed.
This will send a GET or POST request to yourfile.php and then you can manipulate the cell rows in whatever manner you would like and send back a result by echoing it out in the PHP file. You can retrieve the results by making the callback function.
Hope this helps,
Chris