Am trying to parse a php array into javascript but i found that only one element of the array was present in the javascript array. here is my code code
the foreach loop worked just fine printing all the keys and values in the database but in the process of parsing it i seem to be doing something wrongly
cos the alert is only printing the value the last key "5000"
Code:
<?php
include("../../connect.php");
$qry="select * from stock";
$rst=mysql_query($qry) or die("Error in Query.".$qry." ".mysql_error());
while($row=mysql_fetch_assoc($rst)){
$item=$row['item'];
$list[$item]=$row['price'];
}
foreach($list as $key =>$value){
echo $key."-";
echo $value."<br/>";
}
echo $list['coke'];
?>
<script type="text/javascript" language="javascript">
list = new Array("<?php echo $list[$item]; ?>")
alert(list);
</script>
cos the alert is only printing the value the last key "5000"
Comment