tags:

views:

36

answers:

2

I have birth date data stored in Mysql table as below:

id firstname middlename lastname   birth
---------------------------------------------
 1 Harry     Chandra    Sihombing  1999-12-14
 2 Janice    Mona       Sihombing  2010-04-20
 .  ...      ...        ...        ...

How can I create a search function to collect data from the table and restrict the output to rows "where age > 25" (and/or other function using ">" (greater) "=" (equal).

A: 

maybe something like this with DATE_SUB

SELECT * FROM people WHERE DATE_SUB(NOW(),INTERVAL 25 YEAR) > birth

in php:

$age = (int)$_POST['age'];
$sql = "SELECT * FROM people WHERE DATE_SUB(NOW(),INTERVAL $age YEAR) > birth";
Thanks, your script doing right. but i want using number interval form variable passing by field search.
Chandra
im not sure i follow...
the script become:DATE_SUB(NOW(),INTERVAL $search YEAR) < birth I'm get this error: You have an error in your SQL syntax;Note: $search are value submitted from input text.
Chandra
ah you need the php code, i edited it
Thanks it's solved my problems.
Chandra
A: 

Here's a hint:

SELECT NOW(),
    DATE(NOW()),
    DATE_SUB(NOW(), INTERVAL 25 YEAR),
    DATE(DATE_SUB(NOW(), INTERVAL 25 YEAR))
Álvaro G. Vicario