1
I’m making a very simple filter system using PHP
and mysql
.
$stmt = $conexao->prepare("select * from filme where genero = '$genero'");
I’m wanting to put one on the list of genres that, when selected, displays all the movies.
I know that I could easily do this using if/Else:
if ($genero == "todos"){
$stmt = $conexao->prepare("select * from filme");
}else{
$stmt = $conexao->prepare("select * from filme where genero = '$genero'");
}
But I wanted to know if there is any other way to do this if the system gets much more complex and if/Else gets too big. For example, if you wanted to filter the films also by year of release, director and indicative rating, all at the same time and with the same option to display all.
How could I do that?
Thanks for your answers
What you can do is concatenate the query while the filter is selected. If there is no filter it will select from the basic select only
– gabrielfalieri
@gabrielfalieri I did not understand very well, could you explain me better?
– Breno Novo
Breno, let’s assume. How do you know that the "generous" has been selected?
– gabrielfalieri
In html there is a select tag with all genres registered, so when the value is changed the program executes an ajax that passes it by url, at least that’s what I did
– Breno Novo