I have tried to implement PHP array into JavaScript but the problem is that it is not converting properly.
For example if PHP array $new_array
has a value of a,q,s,t,u
it is assigning to all the indexes of JavaScript array for example:
js_array[0]=a,q,s,t,u;
js_array[1]=a,q,s,t,u;
js_array[2]=a,q,s,t,u;
js_array[3]=a,q,s,t,u;
js_array[4]=a,q,s,t,u;
js_array[5]=a,q,s,t,u;
This is my PHP code:
$new_array = array(); // create a new array
$sql=mysql_query("SELECT * FROM animate ORDER BY RAND() LIMIT 5") or die("query Field");
while($row=mysql_fetch_array($sql)){
$new_array[] = $row['code'];
}
js code
var array =[<?php echo json_encode($new_array);?>];
alert(array[0]);
for(var i=0; i <=9 ; i++)
{
array[i]=[<?php echo json_encode($new_array);?>];
}
I want to assign values like:
array[0]=a;
array[1]=q;
array[2]=s;
array[3]=t;
array[4]=u;
I want to do in this pattern but it is not working.