1
I’m making a query in MYSQL that brings the emails that were sent. These emails are in the email column, separated by comma, as in the email table below.
emailsenviados
IDenvio|emails
1 |[email protected],[email protected],[email protected]
2 |[email protected]
Then I need to use these emails that I’m taking as an array to do another query that will bring the names of the people in these emails, who are in the users table
ID| nome |email
1 | João |[email protected]
2 | Maria |[email protected]
3 | José |[email protected]
Is there any way I can get a single consult or is it two? At first what I thought was to make the first consultation and to make an explosion of the results to make a second consultation, but I stopped.
My query is made like this:
$query=("SELECT id FROM emailsenviados WHERE IDenvio=1");
$db -> setQuery($query);
$incs = $db->loadResult();
and the second:
$query=("SELECT name FROM users WHERE >>AQUI SERIA A CONDIÇÃO PARA ENCONTRAR OS EMAILS<<");
$db -> setQuery($query);
$results = $db -> loadObjectList();
foreach($results as $row){
echo $nome.'<br/>';
}
Thank you David, I did it, but came the bame blank
– Leandro Marzullo
The right is to come an array of Names right, one for each user who has e-mail inside the array of emails. It gave some error?
– David Alves
No, I made this query in PHPMYADMIN first to test, switching the variable by valve, then came blank without error: SELECT name FROM users WHERE email IN ("[email protected],[email protected],[email protected]")
– Leandro Marzullo
I tested now instead of email, a number field, there it works, maybe you have to put something because it is text?
– Leandro Marzullo
hmm, yes, the emails have to be in simple quotes, I will correct in the reply
– David Alves
now was, I did so to put the variable, is there another simpler way?: $array_emails='"'. $array_emails. '"'; $array_emails=str_replace(','","',$array_emails);
– Leandro Marzullo
This code you made is a good way out.
– David Alves