I have a query that searches all the id's for a DB. I make WHILE
and put them in $retorno['dados']
. Since there is nothing separating them, they are all together. If I return the id's 41, 45, 50
, I get 414550
. Anyway, now I need to do another search:
SELECT * FROM restaurantes WHERE id=" id's que tenho em $retorno['dados'] "
and put in WHILE
again because I will receive all the data of several lines.
I checked one, but I could not find any answers. What would be the way to do this search?
I have two Tables:
First BD
id | idEmpresa | bairro 01 | 10 | bairro 1 02 | 12 | bairro 2 03 | 20 | bairro 2 04 | 25 | bairro 1
Second BD
id | empresa 10 | empresa a 12 | empresa b 20 | empresa c 25 | empresa d
I get information neighborhood and I consult which companies that serve in this neighborhood:
Receiving for example neighborhood 1 , I know that businesses with id 10 and 25 serve in that neighborhood. So I need to get the Second BD information from companies with id 10 and 25 .
These are the two queries I'm using.
$retorno = array();
$retorno['dados'] = '';
$retorno['dados2'] = '';
$sql2 = "SELECT * FROM endereco_atendimento WHERE bairro='Vila A'";
$buscar2 = $conexao->prepare($sql2);
$buscar2->execute();
$buscar2->rowCount();
while($conteudo2 = $buscar2->fetchObject()){
$retorno['dados2'] .= $conteudo2->idEmpresa;
}
$lista = $retorno['dados2'];
$sql = "SELECT * FROM restaurantes WHERE id='$lista'";
$buscar = $conexao->prepare($sql);
$buscar->execute();
$buscar->rowCount();
while($conteudo = $buscar->fetchObject()){
$retorno['dados'] .= $conteudo->Nome;
}