- Hi, it's my first posting, I hope you can understand me clearly. -
I have 5 variables which are of the Bool type. True or False.
I need to be able to generate a SQL statement depends on the states of the variables.
I was able to generate it in a very extensive way, I wanted to know if there is a function that facilitates the code.
Ex code:
$sql = "SELECT * FROM bitacora WHERE ";
if(($VL_errores == "true") and ($VL_ingresos == "false") and ($VL_config == "false") and ($VL_pesaje == "false") and ($VL_motores == "false")){
$sql .= "codigo LIKE '0%'";
}
if(($VL_errores == "true") and ($VL_ingresos == "true") and ($VL_config == "false") and ($VL_pesaje == "false") and ($VL_motores == "false")){
$sql .= "codigo LIKE '0%' or codigo LIKE '1%'";
}
if(($VL_errores == "true") and ($VL_ingresos == "true") and ($VL_config == "true") and ($VL_pesaje == "false") and ($VL_motores == "false")){
$sql .= "codigo LIKE '0%' or codigo LIKE '1%' or codigo LIKE '2%'";
}
The issue is that I have to generate 32 lines of codes for all possibilities.
Thank you very much!