Greetings to everyone in the community. I'm going through a strange problem. When I select the syntax of the query and colon in PHPMyAdmin, the query returns all the fields I want. But when I put it in the code, it does not return any value.
I have a table of users [users] that contains the company to which it is filled by the field [users]. [emp] that is indexed with the table companies [sjy_empresas] that contains a field that links it to an economic group [sjy_groups]. [group] that is indexed to the group table [sjy_group].
I need to get a list of fields from the flag table [sjy_bandeiras]. [flag] that are contained in the companies table [sjy_empresas]. [flag] if these companies belong to the economic group [sjy_empresas]. user belongs to the field companies [users]. [emp].
I have already tested the $ user variable and it is working.
I'm trying to run this code but the query does not return any value. Where is the error?
$title = BD::conn()->prepare("SELECT 'usuarios'.'usuario_id', 'sjy_grupo'.'id_grupo' FROM 'sjy_grupo' INNER JOIN 'sjy_empresas' ON 'sjy_grupo'.'id_grupo' = 'sjy_empresas'.'grupo' INNER JOIN 'usuarios' ON 'sjy_empresas'.'id_empresa' = 'usuarios'.'emp' WHERE 'usuario_id' = ? GROUP BY 'usuarios'.'usuario_id', 'sjy_grupo'.'id_grupo' LIMIT 0, 1");
$title->execute(array($usuario));
$dados = $title->fetch();
$grupo = $dados['id_grupo'];
$query = "SELECT sjy_grupo.id_grupo, sjy_bandeira.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
GROUP BY sjy_grupo.id_grupo, sjy_bandeira.id_bandeira, sjy_bandeira.bandeira";
$result = mysql_query($query);
while($fetch = mysql_fetch_row($result)){
echo "<option value='?id=724&band=". $fetch[0] . "'>" . $fetch[2] . "</option>";
}