here is a PHP code I am using to fetch pollution data:
<?php
$pol = file_get_contents('https://api.openaq.org/v1/latest/?city=Delhi');
$poldata = json_decode($pol);
$polres = $poldata->results;
$polcnt = count($polres);
$pm10 = 0;
$cnt = 0;
for ($x=0; $x < $polcnt; $x++){
foreach ($polres[$x] as $v){
$m = $v->measurements;
$z = count($m);
foreach ($m as $k){
for ($y = 0; $y < $z; $y++){
if($k->parameter == "pm10"){
$pm10 += $k->value;
$cnt++;
}
}
}}
}
$pm10 /= $cnt;
$tst = "Test";
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<p><?php echo $tst; ?></p>
<p><?php echo $pm10; ?></p>
</body>
</html>
I am getting following warning messages:
Warning: count(): Parameter must be an array or an object that implements Countable in /home2/mridulmishra/public_html/delpollution/index.php on line 12
Warning: Invalid argument supplied for foreach() in /home2/mridulmishra/public_html/delpollution/index.php on line 13
And it's not working. Just showing NAN at the end. Could anyone help, please!