Jump to content

Help With Jquery And Loops


jbwebdesign

Recommended Posts

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 by jbwebdesign
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...