0
I have 3 tables: "Third parties", "Address third", "Contacts third party". The goal was: a third party would be inserted, it would be listed, it would be assigned an address and a contact, however I would like it to be possible to assign several addresses to a single third party. I first used INNER JOIN in the 3 tables and it was not possible, I switched to LEFT JOIN and when more than one address or contact to a third party was listed the same information more than once, I ended up using RIGHT JOIN and FULL JOIN and nothing. `
//Tabela Terceiros
$sql="SELECT Terceiros.*, Email, Telefone, Telemovel, TipoC, Morada, Localidade, CodPostal FROM ((Terceiros INNER JOIN Contactos_Terceiro on Terceiros.Numero = Contactos_Terceiro.Numero ) INNER JOIN Morada_Terceiro on Terceiros.Numero = Morada_Terceiro.Numero )";
if(isset($pesq))
$sql.=" where Nome like '$pesq' ";
$sql.=" limit $ini, $tp";
$res=$lig->query($sql);
//Tabela Contactos_Terceiro
$sql="SELECT Contactos_Terceiro.*, Nome FROM Contactos_Terceiro INNER JOIN Terceiros on (Terceiros.Numero = Contactos_Terceiro.Numero)";
if(isset($pesq))
$sql.=" where Nome like '$pesq'";
$sql.=" limit $ini, $tp";
$res=$lig->query($sql);
//Tabela Morada_Terceiro
$sql="SELECT Morada_Terceiro.*, Nome FROM Morada_Terceiro INNER JOIN Terceiros on (Terceiros.Numero = Morada_Terceiro.Numero)";
if(isset($pesq))
$sql.=" where Nome like '$pesq'";
$sql.=" limit $ini, $tp";
$res=$lig->query($sql);
The problem is that I need the query in the remaining tables because I will fetch the table name field "Third party"
– Someone
But in the others you can use the
join
without worrying about duplicating records.– Ronaldo Araújo Alves
So how would you do it? Leave it as it is in the Third Party table and the other 2?
– Someone
On this Third Party Listing page
select
only from the Third Party table; then when you click the button, you pass theIdTerceiro
as parameter and makes a second query searching the data you need regarding thisIdTerceiro
– Ronaldo Araújo Alves
<?php $sql= "SELECT Third Party., Email, Telephone, Telemovel, Tipoc, Address, Locality, Codpostal from Terceiros, Contactos_terceiro, Address_terceiro "; $sql.=" WHERE Contactos_terceiro.Codcon = Terceiros.Codcon and Address_terceiro.Numero = Terceiros.Numero "; $res=$lig->query($sql); while ($Lin=$res->fetch_array()){ ?>* I tried to do so to the button, but gives error
– Someone
What error? And you need to pass the Id of the selected item.
– Ronaldo Araújo Alves