Habe nochmal eine kleine Frage für zwischendrin:
Ich möchte gerne die Anzahl männlicher und weiblicher Mitglieder ermitteln, sowie im zweiten Code die Anzahl von verschiedenen Altersgruppen. Ich bekomme aber verschiedene Mitgliedergesamtzahlen raus. Wo ist der Fehler in der Abfrage?
Vielen Dank!
PS: Schickes neues Forum!
Code: Alles auswählen
$sql = 'SELECT COUNT(*)
FROM '. TBL_MEMBERS. ' mem, '. TBL_ROLES. ' rol, '. TBL_CATEGORIES. ' cat, '. TBL_USER_DATA. ', '. TBL_USER_FIELDS. '
WHERE mem.mem_rol_id = rol.rol_id
AND mem_begin <= "'.DATE_NOW.'"
AND mem_end >= "'.DATE_NOW.'"
AND mem_leader = 0
AND rol_valid = 1
AND rol_visible = 1
AND rol_cat_id = cat_id
AND rol_id = 2
AND usd_usr_id = mem_usr_id
AND usd_usf_id = usf_id
AND usf_name_intern = "GENDER"
AND usd_value = '.$gender.'
';
Code: Alles auswählen
//Calculate members
$data;
for ($i = 0; $i < 4; $i++) {
switch($i)
{
case 0: $calculated_birthday1 = (intval(date("Y"))-20).'-'.date("m").'-'.date("d");
$calculated_birthday2 = (intval(date("Y"))-14).'-'.date("m").'-'.date("d");
break;
case 1: $calculated_birthday1 = (intval(date("Y"))-25).'-'.date("m").'-'.date("d");
$calculated_birthday2 = (intval(date("Y"))-20).'-'.date("m").'-'.date("d");
break;
case 2: $calculated_birthday1 = (intval(date("Y"))-30).'-'.date("m").'-'.date("d");
$calculated_birthday2 = (intval(date("Y"))-25).'-'.date("m").'-'.date("d");
break;
case 3: $calculated_birthday1 = (intval(date("Y"))-35).'-'.date("m").'-'.date("d");
$calculated_birthday2 = (intval(date("Y"))-30).'-'.date("m").'-'.date("d");
break;
}
$sql = 'SELECT COUNT(*)
FROM '. TBL_MEMBERS. ' mem, '. TBL_ROLES. ' rol, '. TBL_CATEGORIES. ' cat, '. TBL_USER_DATA. ', '. TBL_USER_FIELDS. '
WHERE mem.mem_rol_id = rol.rol_id
AND mem_begin <= "'.DATE_NOW.'"
AND mem_end >= "'.DATE_NOW.'"
AND mem_leader = 0
AND rol_valid = 1
AND rol_visible = 1
AND rol_cat_id = cat_id
AND rol_id = 2
AND usd_usr_id = mem_usr_id
AND usd_usf_id = usf_id
AND usf_name_intern = "BIRTHDAY"
AND usd_value > "'.$calculated_birthday1.'"
AND usd_value < "'.$calculated_birthday2.'"
';
$db_result = $g_db->query($sql);
//Fill array
$row = $g_db->fetch_array($db_result);
$data[$i] = $row[0];
}