I have a problem when I try to implement a date filter:
My database is something like this:
start_date | end_date
2000 | 2005
My PHP select looks like this:
if (empty($processo) && empty($ano)){
$pegaSonda = $pdo->prepare("SELECT * FROM sonda WHERE `modelo` = ?");
$pegaSonda->execute();
} else if(!empty($processo) && empty($ano)) {
$pegaSonda = $pdo->prepare("SELECT * FROM sonda WHERE n_processo = '$processo'");
$pegaSonda->execute();
} else if(!empty($processo) && !empty($ano)){
//AQUI EU POSSO COLOCAR O FILTRO POR ANO
$pegaSonda = $pdo->prepare("SELECT * FROM sonda WHERE n_processo = '$processo'");
$pegaSonda->execute();
}
The variable $ano (this is the year that the user will write in a input text and the ajax will send to PHP as Post request).
How can I use the SELECT when the user types the year?
The code I've tried looks like this:
"SELECT * FROM sonda WHERE n_processo = '$processo' AND start_date >= '$ano' OR end_date <= '$ano'"
Any help please? Thanks!