Referring to the title. I have an array which I coded like this:-
$query = "SELECT * FROM server";
$result = mysql_query($query);
$dServer = array();
while($row = mysql_fetch_assoc($result)) {
$dServer[] = $row['model'];
}
Now, how do I pass the $dServer array into a Javascript array?
For example, this array:
var a = new Array();
$query = "SELECT * FROM server";
$result = mysql_query($query);
$dServer = array();
while($row = mysql_fetch_assoc($result)){
$dServer[] = $row['model'];
}
?>
<script type="text/javascript">
var a = <?php echo json_encode($dServer); ?>;
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With