1
Greetings to everyone in the community. I’m going through a strange problem. When I select query syntax and paste in Phpmyadmin, the query returns all the fields I want. But when I put it in the code, it doesn’t return any value.
I have a table of users [users] that contains the company to which it is crowded by the [users] field. [emp] that is indexed with the table companies [sjy_companies] that contains a field that links to an economic group [sjy_companies]. [group] which is indexed to the group table [sjy_group].
I need to get a list of fields from the flag table [sjy_flags]. [flag] that are contained in the companies table [sjy_companies]. [flag] if these companies belong to the economic group [sjy_companies]. [group] to which the user belongs based on the companies [users] field. [emp].
I already tested the $user variable and it’s working.
I am trying to execute 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>";
}
Is mixing
mysql_
(Old PHP API and discontinued) with mysqli (new php API), so it will never work, both Apis do not communicate.– Guilherme Nascimento