1,105,585 Community Members

How to increment php array variable inside javascript...

Member Avatar
druveen
Newbie Poster
10 posts since Jan 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi everyone

$i=0;
echo '<script language="javascript">
var dA = new Array();
var x = 0;

for(i=0;i<2;i++)
{

	dA[x++]="'.$date[$i]." ".$message[$i].'";
		'.$i++.';
	
}


</script>';

here i want to increment $i above code is not working, Please help...Thanks in Advance...

Member Avatar
scrappedcola
Posting Whiz in Training
219 posts since Dec 2009
Reputation Points: 11 [?]
Q&As Helped to Solve: 45 [?]
Skill Endorsements: 0 [?]
 
0
 

You can't execute a client side(javascript) for loop on the server side(php). You can print javascript out incrementally that would be an array of size 2 using a for loop on your server side. For instance:

$i = 0;
echo '<script type=text/javascript>';
echo 'var dA = new Array();';
for ($i = 0; $i < 2; $i++)
{
    echo 'dA['.$i.'] = "'.$date[$i].$message[$i].'";';
}
echo '</script>';
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article