I am trying to create a query string based on GET values passed to common vars:
if isset, gTipo = $_GET['tipo'] and others like this.
So, here is the code that is not working:
$sqlLista = 'SELECT * FROM produtos';
if($gTipo <> 0 || $gLinha <> 0)
{
if($gtipo <> 0 && $gLinha == 0 )
{
$sqlLista .= ' WHERE id_tipo = '.$gTipo.'';
}
if($gtipo <> 0 && $gLinha <> 0)
{
$sqlLista .= ' WHERE id_tipo = '.$gTipo.' AND id_linha = '.$gLinha.'';
}
if($gTipo == 0 && $gLinha <> 0)
{
$sqlLista .= ' WHERE id_linha = '.$gLinha.'';
}
}
If i set my url as ?tipo=2&linha=4 , my script capture this GET vars and create the common var gTipo and gLinha. If any of this GET are not set, the gTipo or gLinha receive the '0' (zero) value.
When I run the script of query building, nothing is concatened to $sqlLista, except what is done outside the if ( $sqlLista = 'SELECT * FROM produtos'; ).
I am sure this must be a stupid thing that I cannot see. Please, help me =)