1
I am trying to create a query criteria selection engine. For example:
I have a mass of data where the following variables exist:
- store code
- Brazilian state in which it is located
- Brazilian region in which it is located
- Flag of products that the store distributes
- date of sale
- value
The field I wish to return is that of value, provided that one or more of the above criteria has (m) been met(s). I didn’t want to create all varieties of possible combinations between these 5 fields. So I wanted to know:
It is possible to use wildcard characters (type *) as query criteria?
Then I could define the variables as follows:
if(isset($_GET['uf'])){ // Estado brasileiro
$uf = $_GET['uf'];
} else {
$uf = "*";
}
if(isset($_GET['rg'])){ // Região brasileira
$rg = $_GET['rg'];
} else {
$rg = "";
}
if(isset($_GET['ini']) && $_GET['fim'] ){ // data incicial
$ini = $_GET['ini'];
} else {
$ini = "01/01/2017";
$fim = date("d-m-Y");
}
if(isset($_GET['band'])){ // bandeira
$band = $_GET['band'];
} else {
$band = "*";
}
And then assemble a single query that can meet any criteria set or not:
$qry = "SELECT sjy_grupo.id_grupo, sjy_empresas.bandeira AS id_bandeira, sjy_bandeira.bandeira
FROM sjy_bandeira INNER JOIN
sjy_grupo INNER JOIN sjy_empresas ON sjy_grupo.id_grupo = sjy_empresas.grupo
AND sjy_bandeira.id_bandeira = sjy_empresas.bandeira
WHERE id_grupo = '$grupo'
AND id_bandeira = '$id_bandeira'
GROUP BY sjy_grupo.id_grupo, sjy_bandeira.id_bandeira, sjy_bandeira.bandeira";
The wildcard characters would be on account of WHERE id_group = '$group' AND id_flag = '$id_flag', right?
– Brunno Vianna
Exactly Brunno. I want to avoid the trouble of having to create a query for each possibility of combinations between these variables
– Webster Moitinho
If the answer helped you, please accept it as correct
– Brunno Vianna
@Runno could not find where accepted as correct
– Webster Moitinho
just below the title of my answer, on the left, has two arrows and a "check" sign, which turns green when you put the mouse on top.
– Brunno Vianna