Searchf for Min and Max Age php Mysqli
I already tried many times to look for information about searching in php
for min and max age from mysql database, but i can't find right
information what i need. First, i will explain what i mean and what i
want.
My database is as follows:
Db Name: Db_Name Table: users Column: age
I am writing a php script to let give a user option to fill in what he/she
want to search from (min)age to (max)age and as result, he gets a list
that shows all users from that (min)age to (max)age.
Example, he/she selected: 21-30 Then the list shows users with age:
21,22,23,24,25,26,27,28,29,30
For now, what i already did try is this:
<?php
$db = new mysqli('localhost', 'root', '', 'traindb');
$db->select_db("traindb");
if($db->connect_errno > 0) {
die('Er is een fout opgetreden: ' . $db->connect_error);
}
function leeftijden($age) {
$morgen['day'] = date('d');
$morgen['month'] = date('m');
$morgen['year'] = date('Y') - $age;
$datum = $morgen['day'] .'-' .$morgen['month'].'-' .$morgen['year'];
return $datum;
}
$maxDatum = leeftijden(18);
$minDatum = leeftijden(32);
$sqlRijder = 'SELECT * FROM users WHERE age BETWEEN CURDATE() - INTERVAL
'.$minDatum.' YEAR AND CURDATE() - INTERVAL '.$maxDatum.' YEAR';
if ($result = $db->query($sqlRijder)) {
printf("Select returned %d rows.\n", $result->num_rows);
$result->close();
}
$db->close();
?>
As result i get: Select returned 0 rows.
What am i doing wrong? Can anyone explain me how to this in right way?
Thanks!
No comments:
Post a Comment