Jump to content

Exporting PHP arrays


joquius

Recommended Posts

Just found this code quite useful for using predefined php values out of mysql, while using java to prevent reloading the page. Works exceptionally well.An example for an x,y key multidimensional array export:example array value; $array[3][4] = "#f0f0f0";

<?function load_schemes (){	if ($schemes = mysql_query ("select distinct `scheme` from `colors` where 1"))	{  while ($scheme = mysql_result ($schemes, 0))  { 	 $result = mysql_query ("select * from `colors` where `scheme` = '$scheme'"); 	 while ($_result = mysql_fetch_array  ($result)) 	 {    $array[$_result['y']][$_result['x']] = $_result['color']; 	 } 	 ?><script type="text/javascript">var array_<?=$scheme?> = new Array()</script><? 	 foreach ($array as $y => $value) 	 {    ?><script type="text/javascript">array_<?=$scheme?>['<?=$y?>'] = new Array()</script><?    foreach ($array as $x => $_value)    {   	 ?><script type="text/javascript">array_<?=$scheme?>['<?=$y?>']['<?=$x?>'] = "<?=$_value?>"</script><?    } 	 }  }	}}?>

I use this for colouring specific cells in a table with a large number of cells when you don't want to reload the table for each change. Once you export these you can then just reload different color arrays as needed within a java script.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...