$host="localhost";
$user="####";
$pass="####";
$db_name="net";
$link=mysql_connect($host,$user,$pass);
mysql_select_db($db_name,$link);
$sql = mysql_query("SELECT `packets` , `bytes` FROM `table`", $link);
while ($result = mysql_fetch_array($sql)) {
echo $result['packets'];
}
<?php
$pass = [];
$array = [
"name" => "value",
"anotherName" => "anotherValue"
];
foreach($array as $key => $value){
if (array_key_exists($key, $pass)) {
$pass[$key] = array_merge_recursive($pass[$key], $value);
} else {
$pass[$key] = $value;
}
}
?>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
const variable = $.extend({}, <?= json_encode($pass) ?> );
$(function(){
$(".result").html(variable.anotherName);
});
</script>
</head>
<body>
<div class="result"></div>
</body>
</html>