Durch "try & error" habe ich nun folgenden funktionierenden Code "zusammengebastelt". Vielleicht hilft er ja jemandem....
Code: Alles auswählen
<style>
#Main { display: flex ; }
.iMain { width: 3048px ; }
#gruppe { display: ;}
.igruppe { float: left; width: 200px }
#mann { display: ; }
.imann { float: left; width: 100px ; text-align: left; }
#frau { display: ; }
.ifrau { float: left; width: 100px ; text-align: left; }
#total { display: ; }
.itotal { float: left; width: 100px ; text-align: left; }
#WannAct { display: ; }
.iWannAct { float: left; width: 10px ; text-align: left; }
</style>
<?php
date_default_timezone_set('Europe/Berlin');
setlocale(LC_TIME, "de_DE");
defined('_JEXEC') or die('Restricted access');
# header("Content-Type: image/jpeg");
error_reporting(0);
require_once ('admidio/adm_my_files/confix.php');
$gDb = mysqli_connect (
$g_adm_srv,
$g_adm_usr,
$g_adm_pw,
$g_adm_db
);
if ( $gDb )
{
# echo "Verbindung erfolgreich: ";
# print_r( $db_link);
}
else
{
// hier sollte dann später dem Programmierer eine
// E-Mail mit dem Problem zukommen gelassen werden
die('keine Verbindung möglich: ' . mysqli_error());
}
$gDb->set_charset('utf8');
$ehrenmitglieder = 0;
$passivmitglieder = 0;
$familien_passivmitglieder = 0;
$aktiv_ehrenmitglieder = 0;
$anzahl_mitglieder = 0;
$anzahl_maenner = 0;
$anzahl_frauen = 0;
$anzahl_sonstige = 0;
$alter_mitglieder = 0;
$alter_maenner = 0;
$alter_frauen = 0;
$juengster = 200;
$aeltester = 0;
$m14 = 0;
$m18 = 0;
$m26 = 0;
$m40 = 0;
$m60 = 0;
$m65 = 0;
$m66 = 0;
$w14 = 0;
$w18 = 0;
$w26 = 0;
$w40 = 0;
$w60 = 0;
$w65 = 0;
$w66 = 0;
function Geburtstag($gebdat)
{
$tag = substr($gebdat,8,2);
$monat = substr($gebdat,5,2);
$jahr = substr($gebdat,0,4);
$jetzt = mktime(0,0,0,date("m"),date("d"),date("Y"));
$gb = mktime(0,0,0,$monat,$tag,$jahr);
$alter = intval(($jetzt - $gb) / (3600 * 24 * 365));
return $alter;
}
$ergehre = $gDb->query("SELECT usr_id,
CONCAT(id2.usd_value, ' ',id1.usd_value) AS name, CONCAT(id4.usd_value, ' ', id5.usd_value) AS ort, rol_id, rol_sequence, rol_name, YEAR(mem_begin), YEAR(mem_end)
FROM adm_roles, adm_categories, adm_members, adm_users
LEFT JOIN adm_user_data id1 ON id1.usd_usr_id = usr_id
AND id1.usd_usf_id = 1
LEFT JOIN adm_user_data id2 ON id2.usd_usr_id = usr_id
AND id2.usd_usf_id = 2
LEFT JOIN adm_user_data id4 ON id4.usd_usr_id = usr_id
AND id4.usd_usf_id = 4
LEFT JOIN adm_user_data id5 ON id5.usd_usr_id = usr_id
AND id5.usd_usf_id = 5
WHERE rol_id = 21 AND mem_begin <= NOW() AND mem_end > NOW()
AND rol_valid = 1
AND rol_cat_id = cat_id
AND cat_org_id = 1
AND mem_rol_id = rol_id
AND mem_usr_id = usr_id
AND usr_valid = 1
ORDER BY name ASC");
while ($zeile2 = $ergehre->fetch_object()) {
$ehrenmitglieder ++;
$auswertung [$zeile2->usr_id]=$zeile2->name;
}
$ergpass = $gDb->query("SELECT usr_id,
CONCAT(id1.usd_value, ' ', id2.usd_value) AS name, CONCAT(id4.usd_value, ' ', id5.usd_value) AS ort, CONCAT(id70.usd_value) AS betrag, rol_id, rol_sequence, rol_name, YEAR(mem_begin), YEAR(mem_end)
FROM adm_roles, adm_categories, adm_members, adm_users
LEFT JOIN adm_user_data id1 ON id1.usd_usr_id = usr_id
AND id1.usd_usf_id = 1
LEFT JOIN adm_user_data id2 ON id2.usd_usr_id = usr_id
AND id2.usd_usf_id = 2
LEFT JOIN adm_user_data id4 ON id4.usd_usr_id = usr_id
AND id4.usd_usf_id = 4
LEFT JOIN adm_user_data id5 ON id5.usd_usr_id = usr_id
AND id5.usd_usf_id = 5
LEFT JOIN adm_user_data id70 ON id70.usd_usr_id = usr_id
AND id70.usd_usf_id = 70
WHERE rol_id = 18 AND mem_begin <= NOW() AND mem_end > NOW()
AND rol_valid = 1
AND rol_cat_id = cat_id
AND cat_org_id = 1
AND mem_rol_id = rol_id
AND mem_usr_id = usr_id
AND usr_valid = 1
ORDER BY name ASC");
while ($zeile3 = $ergpass->fetch_object()){
$passivmitglieder ++;
if ($zeile3->betrag > 15)
{
$familien_passivmitglieder ++;
}
}
$erg = $gDb->query("SELECT usr_id, id1.usd_value, id2.usd_value, id5.usd_value, id10.usd_value, id11.usd_value, rol_id
FROM adm_roles, adm_categories, adm_members, adm_users
LEFT JOIN adm_user_data id1 ON id1.usd_usr_id = usr_id
AND id1.usd_usf_id = 1
LEFT JOIN adm_user_data id2 ON id2.usd_usr_id = usr_id
AND id2.usd_usf_id = 2
LEFT JOIN adm_user_data id5 ON id5.usd_usr_id = usr_id
AND id5.usd_usf_id = 5
LEFT JOIN adm_user_data id10 ON id10.usd_usr_id = usr_id
AND id10.usd_usf_id = 10
LEFT JOIN adm_user_data id11 ON id11.usd_usr_id = usr_id
AND id11.usd_usf_id = 11
WHERE rol_id = 2 AND mem_begin <= NOW() AND mem_end > NOW()
AND rol_valid = 1
AND rol_cat_id = cat_id
AND cat_org_id = 1
AND mem_rol_id = rol_id
AND mem_usr_id = usr_id
AND usr_valid = 1
ORDER BY id1.usd_value ASC");
// $erg->execute;
while ($user = $erg->fetch_array()) {
// Anzahl und Alter der Männer / Frauen
$geschlecht = ($user[5]);
$geburtstag = Geburtstag($user[4]);
$wohnort = ($user[3]);
if($wohnort == 'Uttigen')
{
$uttiger++;
}
else
{
$andere++;
}
if($geschlecht == 1)
{
$anzahl_maenner++;
$alter_maenner = $alter_maenner+$geburtstag;
if ($geburtstag<=14)
{
$m14 ++;
}
elseif (($geburtstag>14) and ($geburtstag<=18))
{
$m18 ++;
}
elseif (($geburtstag>18) and ($geburtstag<=26))
{
$m26 ++;
}
elseif (($geburtstag>26) and ($geburtstag<=40))
{
$m40 ++;
}
elseif (($geburtstag>40) and ($geburtstag<=60))
{
$m60 ++;
}
elseif (($geburtstag>60) and ($geburtstag<=65))
{
$m65 ++;
}
else
{
$m66 ++;
}
}
else if($geschlecht == 2)
{
$anzahl_frauen++;
$alter_frauen = $alter_frauen+$geburtstag;
if ($geburtstag<=14)
{
$w14 ++;
}
elseif (($geburtstag>14) and ($geburtstag<=18))
{
$w18 ++;
}
elseif (($geburtstag>18) and ($geburtstag<=26))
{
$w26 ++;
}
elseif (($geburtstag>26) and ($geburtstag<=40))
{
$w40 ++;
}
elseif (($geburtstag>40) and ($geburtstag<=60))
{
$w60 ++;
}
elseif (($geburtstag>60) and ($geburtstag<=65))
{
$w65 ++;
}
else
{
$w66 ++;
}
}
if($geburtstag > $aeltester)
{
$aeltester = $geburtstag;
}
if($geburtstag < $juengster)
{
$juengster = $geburtstag;
}
}
$erg3 = $gDb->query("SELECT usr_id,
CONCAT(id2.usd_value, ' ',id1.usd_value) AS name, rol_id, YEAR(mem_begin) AS rol_anf, YEAR(mem_end) AS rol_end
FROM adm_roles, adm_categories, adm_members, adm_users
LEFT JOIN adm_user_data id1 ON id1.usd_usr_id = usr_id
AND id1.usd_usf_id = 1
LEFT JOIN adm_user_data id2 ON id2.usd_usr_id = usr_id
AND id2.usd_usf_id = 2
WHERE (rol_id =2 AND mem_begin <= NOW() AND mem_end > NOW())
AND rol_valid = 1
AND rol_cat_id = cat_id
AND cat_org_id = 1
AND mem_rol_id = rol_id
AND mem_usr_id = usr_id
AND usr_valid = 1
ORDER BY usr_id ASC");
while ($zeile3 = $erg3->fetch_object()) {
$pos = array_search(($zeile3->name), $auswertung,true);
if ($pos===false)
{
}
else
{
$aktiv_ehrenmitglieder++;
}
}
// echo "<h1>Statistik von unserem Verein</h1>";
// echo "<br>";
echo "Stand am " .date("d.m.Y");
echo "<br>";
echo "Anzahl Aktiv-Mitglieder: ". ($anzahl_frauen+$anzahl_maenner);
echo "<br>";
echo "Anzahl Frauen: ". $anzahl_frauen;
echo "<br>";
echo "Anzahl Männer: ". $anzahl_maenner;
echo "<br>";
echo "Durchschnittsalter: ". round((($alter_maenner+$alter_frauen)/($anzahl_frauen+$anzahl_maenner)),1);
echo "<br>";
echo "Durchschnittsalter Frauen: ". round(($alter_frauen/$anzahl_frauen),1);
echo "<br>";
echo "Durchschnittsalter Männer: ". round(($alter_maenner/$anzahl_maenner),1);
echo "<br>";
echo "Jüngstes Mitglied: ". $juengster;
echo "<br>";
echo "Ältestes Mitglied: ". $aeltester;
echo "<br>";
echo "wohnhaft in Uttigen: ". $uttiger;
echo "<br>";
echo "Auswärtige: ". $andere;
echo "<br>";
echo "Anzahl Ehren-Mitglieder: ". ($ehrenmitglieder);
echo "<br>";
echo "davon aktiv: ". ($aktiv_ehrenmitglieder);
echo "<br>";
echo "Anzahl Passivmitglieder: ". ($passivmitglieder);
echo "<br>";
echo "davon Familien-Mitglieder: ". ($familien_passivmitglieder);
echo "<br>";
echo "<br>";
echo "<h1>Altersgruppen</h1>";
echo "<br>";
?>
<div id="Main">
<div class="igruppe">Altersgruppe</div>
<div class="imann">Männlich</div>
<div class="ifrau">Weiblich</div>
<div class="itotal">Total</div>
</div>
<div id="Main">
<div class="igruppe">bis 14 Jahre</div>
<div class="imann"><?=$m14;?></div>
<div class="ifrau"><?=$w14;?></div>
<div class="itotal"><?=($m14 + $w14);?></div>
</div>
<div id="Main">
<div class="igruppe">15 - 18 Jahre</div>
<div class="imann"><?=$m18;?></div>
<div class="ifrau"><?=$w18;?></div>
<div class="itotal"><?=($m18 + $w18);?></div>
</div>
<div id="Main">
<div class="igruppe">19 - 26 Jahre</div>
<div class="imann"><?=$m26;?></div>
<div class="ifrau"><?=$w26;?></div>
<div class="itotal"><?=($m26 + $w26);?></div>
</div>
<div id="Main">
<div class="igruppe">27 - 40 Jahre</div>
<div class="imann"><?=$m40;?></div>
<div class="ifrau"><?=$w40;?></div>
<div class="itotal"><?=($m40 + $w40);?></div>
</div>
<div id="Main">
<div class="igruppe">41 - 60 Jahre</div>
<div class="imann"><?=$m60;?></div>
<div class="ifrau"><?=$w60;?></div>
<div class="itotal"><?=($m60 + $w60);?></div>
</div>
<div id="Main">
<div class="igruppe">61 - 65 Jahre</div>
<div class="imann"><?=$m65;?></div>
<div class="ifrau"><?=$w65;?></div>
<div class="itotal"><?=($m65 + $w65);?></div>
</div>
<div id="Main">
<div class="igruppe">ab 66 Jahren</div>
<div class="imann"><?=$m66;?></div>
<div class="ifrau"><?=$w66;?></div>
<div class="itotal"><?=($m66 + $w66);?></div>
</div>
<div id="Main">
<div class="igruppe">Total</div>
<div class="imann"><?=($m14 + $m18 + $m26 + $m40 + $m60 + $m65 + $m66);?></div>
<div class="ifrau"><?=($w14 + $w18 + $w26 + $w40 + $w60 + $w65 + $w66);?></div>
<div class="itotal"><?=($m14 + $m18 + $m26 + $m40 + $m60 + $m65 + $m66 + $w14 + $w18 + $w26 + $w40 + $w60 + $w65 + $w66);?></div>
</div>
<?php
echo "<br>";
echo "<br>";
## Verbindung schliessen
$erg->free();
$erg3->free();
$gDb->close();
?>