2
Sublime text, Mysql Workbench and Xampp usage.
I made a Join Inner in select below, in a table called Organizations.Copia. In this table there is a field called "id" and I need it to appear in this Php code.
I saw several videos and examples, and could not do. How I put to pull the copy of these returning customers in my variable "$result
"? How do I include that in while?
Follow the code ready:
<?php
$servidor = '****';
$user = '****';
$senha = '****';
$banco = 'Organizacoes';
// Cria conexão
$conn = new mysqli($servidor, $user, $senha, $banco);
// Checa conexão
if ($conn->connect_error) {
die("Conexão falha: " . $conn->connect_error);
}
$sql = "SELECT Org.id
,Org.nome
FROM Organizacoes as Org
INNER JOIN Organizacoes.Rel_Organizacoes as Grupo on Org.id = Grupo.id_Organizacao
INNER JOIN Organizacoes.Copias as Copia on Org.id = Copia.id_Organizacao
WHERE Grupo.id_grupo = 210
GROUP BY Org.id
ORDER BY Org.id";
$result = $conn->query($sql);
echo " <tr>";
if ($result->num_rows > 0) {
// dados de saída de cada linha
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - nome: " . $row["nome"]. " " . "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
query brings the results?
– Wees Smith
Bring, it brings the client name and his code.. This "copy" is an id, but from another table. But I can’t include this "Id.Copy in this current while.
– Fernandinha
is because you didn’t ask to select him
– Wees Smith
So I actually took it to post here because I can’t ride in while.. If I put it in my $result result select Org.id ,Org.name , Copy.id .. How do I put it in while? How do I structure? This part that I’m having difficulty knows?
– Fernandinha
I will be very grateful.. I realized that it is the doubt of many beginners in php.
– Fernandinha
I accidentally deleted my mouse at the end of my life
– Wees Smith
calls the id you want and gives a
var_dump($result)
and look at the structure– Wees Smith
Then I add the id.copy to my $result variable, and put the "var_dump ($result) " after while? Where do I leave it?
– Fernandinha
Could I put a "query2" with "$result2" inside that while? Or do you think it’s better to do it the way you said?
– Fernandinha
may be before while, provided it is dps that $result appeared
– Wees Smith
The var_dump worked?
– Wees Smith
It went in pieces.. He pulled the copy, but replaced my other account id..
– Fernandinha
then the problem is in the nomenclature of the fields of Tablas, this with equal names, just change
– Wees Smith
so you can separate within $Row['id_copy'] from $Row['id']
– Wees Smith
But how do I do it? If I change the name it gives error: Notice: Undefined index: ['id_copia'] in C: xampp htdocs query.php on line 29
– Fernandinha
The name of the fields are equal, but the tables are different. Taba.id, Tabb.id.. Understood?
– Fernandinha
Post the var_dump return
– Anderson Henrique