View Single Post
Old 10-07-2012, 05:04 PM   PM User | #1
Cyberpops
New to the CF scene

 
Join Date: Oct 2012
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Cyberpops is an unknown quantity at this point
passing array from php to javascript

trying to pass several sql query array to further work in JS:

PHP Code:
<?php
$x 
mysql_query("SELECT p_max  FROM dsd_price");
$y mysql_query("SELECT p_min  FROM dsd_price");
$z mysql_query("SELECT p_price  FROM dsd_price");
while (
$x_array mysql_fetch_array($x)){$max[] = $x_array['p_max']; }
while (
$y_array mysql_fetch_array($y)){$min[] = $y_array['p_min']; }
while (
$z_array mysql_fetch_array($z)){$price[] = $z_array['p_price'];}
?>
JS:

Code:
<script type="text/javascript">
function price() {
var max = <?php echo json_encode($max); ?>;  
var min = <?php echo json_encode($min);?>;
var price = <?php echo json_encode($price);?>;
document.write(price + " " + min +" "+ max );
}
</script>
Result:
Quote:
[object Object],[object Object],[object Object],11,15,17 [object Object],[object Object],[object Object],1,6,11 [object Object],[object Object],[object Object],1,10,15
So the problem, as u can see is that it adds those [object, Object] values to my array.
Cyberpops is offline   Reply With Quote