I have a defined array. If is one from column (e.g. Bayern 'by') empty, then i do not receive variable $row_wohn_by and after in result get is: Notice: Undefined variable: row_wohn_by
Simply erase is not a solution for another operate. Expected is defined $row_wohn_by with 0 (zero) number.
Here is code:
$states = array(
'Baden-Württemberg' => 'bw',
'Bayern' => 'by',
'Berlin' => 'be',
'Thüringen' => 'th'
);
$numb_rows = mysqli_query($conn, 'SELECT COUNT(*)
FROM members
WHERE priv_staat = "Deutschland"
');
$numb_row = mysqli_fetch_array($numb_rows);
$total_wohn = $numb_row[0];
$query_wohn = mysqli_query($conn, "SELECT `priv_land`, COUNT(*) AS `count` FROM `members` WHERE `priv_land` !=0 GROUP BY `priv_land`");
while ($item_wohn = $query_wohn->fetch_assoc()) {
${'row_wohn_'.$states[$item_wohn['priv_land']]} = $item_wohn['count'];
${'row_wohn_per_'.$states[$item_wohn['priv_land']]} = number_format((($item_wohn['count'] / $total_wohn)*100), 2, ',', ' '); // calulate in %
}
$row_wohn_all = $total_wohn-($row_wohn_bw + $row_wohn_by + $row_wohn_be + $row_wohn_th);
$row_wohn_per_all = number_format((($row_wohn_all / $total_wohn)*100), 2, ',', ' '); // calulate in %
Thanks for help.