jbwebdesign Posted April 16, 2013 Report Posted April 16, 2013 (edited) hello everyone, i am working on a script and i want to do the following i have a table that looks like this... <table> <tr> <td>Tuesday</td> <td>12/31</td> <td>New Years Eve</td> <td>Test</td> <td>Apples</td> <td>Oranges</td> <td>Bananas</td> </tr> <tr> <td>Monday</td> <td>12/30</td> <td>New Years Eve EVE</td> <td>Test</td> <td>Apples</td> <td>Oranges</td> <td>Bananas</td> </tr> <tr> <td>Sunday</td> <td>12/29</td> <td>New Years Eve Eve EVE</td> <td>Test</td> <td>Apples</td> <td>Oranges</td> <td>Bananas</td> </tr> </table> I want to convert EACH TR into a PHP ARRAY I want the code to look something like this and it does in the console, however i need to output all of it into a string: <?php array( "data" => 0, array( "Tuesday", "12/31", "New Years Eve", "Test", "Apples", "Oranges", "Bananas" ), "data" => 1, array( "Monday", "12/30", "New Years Eve EVE", "Test", "Apples", "Oranges", "Bananas" ), "data" => 2, array( "Sunday", "12/29", "New Years Eve Eve EVE", "Test", "Apples", "Oranges", "Bananas" ), ); ?> My Current Javascript code is as follows: var count = 0; $("#output").find('tr').each(function(){ count++ var array_str = 'array(' + '"data" => "' + count + '", array('; console.log(array_str); $(this).find('td').each(function(value){ var str = '"'+ value +'" => "'+$(this).text()+'",'; //this makes the php array keys //var str = Array(value); console.log(str); }); console.log("));"); }); Can anyone please help me to output the entire console code that gets returned into a string or into a DIV. thanks Edited April 16, 2013 by jbwebdesign
falkencreative Posted April 16, 2013 Report Posted April 16, 2013 Just a quick comment... Are you sure you can do this? PHP code is processed before/as the page loads. Javascript code is only processed after the page loads. For example, you can use PHP to set Javascript variables, but I'm pretty sure you can't use Javascript to create PHP (short of passing a string to PHP via AJAX and then PHP parsing it into an array). Unless you meant this?
jbwebdesign Posted April 16, 2013 Author Report Posted April 16, 2013 well what i am trying to do is take the TABLE and convert it into a php array so that i can insert it into a MySQL database.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now