0
Hello, I have a code where I take the data coming from a webservice and store in variables.
I would like to Inserir/Salvar
that data in my database Mysql. However I get this data through a foreach(){...}
// Pegar os leads
$leads = $client->leads->getLeads([]);
// Pegando os leads
foreach($leads->contacts as $contacts)
{
// Salvando dados nas variáveis
$nome = $contacts->name;
$id = $contacts->id;
$tags = $contacts->tags;
// Percorrendo os dados
foreach($tags->tags as $objeto)
{
$tag = $objeto->name;
}
}
agree with the above code. How I could insert this data so it would look like this in the table [example ] :
[ID] [NOME] [TAGS]
[01] [JOSÉ] [tag1,tag2,tag3..]
For if I create a query like this :
$query = mysqli_query($conexao,"INSERT INTO leads(nome,tags) VALUES ('$nome','$tag')";
each foreach(){..}
would have a tag different and overwrite the value of tag previous.
Check there. There is no WHERE clause in Insert.
– Reginaldo Rigo
Oh my friend, truth I ended up getting confused with the
If(){...}
which checks whether the user exists with theID
if there is update or Insert a new one! Thanks for the remark!– user50712
$contacts->tags
is an array?– Guilherme Nascimento