jbwebdesign Posted April 16, 2013 Report Share 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 Quote Link to comment Share on other sites More sharing options...
falkencreative Posted April 16, 2013 Report Share 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? Quote Link to comment Share on other sites More sharing options...
jbwebdesign Posted April 16, 2013 Author Report Share 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.