1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| function searchFathers($childId, $childName='', $childBirthdate=null, $fatherMinAge=null, $fatherMaxAge=null) {
global $db;
//if (! isset($fatherMinAge, $fatherMaxAge) return false;
var_dump($childId, $childName, $childBirthdate, $fatherMinAge, $fatherMaxAge);
$where = [];
$where[] = "id_abo=:id_abo AND id!=:id AND gender='M'";
$where[] = "((death_date > :childBirthdate - INTERVAL 11 MONTH) OR death_date IS NULL)";
if (isset($fatherMinAge, $fatherMaxAge))
$where[] = "birth_date BETWEEN (:childBirthdate - INTERVAL :fatherMaxAge YEAR) AND (:childBirthdate - INTERVAL :fatherMinAge YEAR)";
if ($childName)
$where[] = "last_name=:last_name";
$strWhere = implode(" AND ", $where);
$strWhere = "WHERE $strWhere";
// Pour test :
//$strWhere = "WHERE id_abo=1 AND id!=$childId AND gender='M' AND ((death_date > '$childBirthdate' - INTERVAL 11 MONTH) OR death_date IS NULL) AND birth_date BETWEEN ('$childBirthdate' - INTERVAL $fatherMaxAge YEAR) AND ('$childBirthdate' - INTERVAL $fatherMinAge YEAR) AND last_name='$childName'";
$strWhere = "WHERE id_abo=1 AND id!=88 AND gender='M' AND ((death_date > '2000-01-01' - INTERVAL 11 MONTH) OR death_date IS NULL) AND birth_date BETWEEN ('2000-01-01' - INTERVAL 55 YEAR) AND ('2000-01-01' - INTERVAL 19 YEAR) AND last_name='Démo'";
var_dump($strWhere);
$query = "
SELECT id, last_name, first_name, middle_name, birth_date, death_date
FROM dat_persons
$strWhere
;";
$result = $db->prepare($query);
$result->bindParam('id_abo', $_SESSION['user']['id_abo']);
$result->bindParam('id', $childId);
$result->bindParam('childBirthdate', $childBirthdate);
if ($childName)
$result->bindParam('last_name', $childName);
if (isset($fatherMinAge, $fatherMaxAge)) {
$result->bindParam('fatherMinAge', $fatherMinAge);
$result->bindParam('fatherMaxAge', $fatherMaxAge);
}
$result->execute();
return $result->fetchAll();
} |
Partager