2
I have a table where each projeto
may be related to up to 4 produtos
.
Main Table (foreign keys):
IDPRODUTO
IDPRODUTO2
IDPRODUTO3
IDPRODUTO4
Table
produtos
ID
NOME
To perform the display, I created a dynamic table. When I do the query, I use JOIN
to bring the product table.
The problem is that I can’t display the name of all four products, only the product name of the first ID that appears. How do I display the product name related to other Ids ?
Mysql query:
SELECT *
FROM principal
JOIN produto on principal.IDPRODUTO and principal.IDPRODUTO2 and principal.IDPRODUTO3 and principal.IDPRODUTO4 = produto.PROD_ID
JOIN responsavel on principal.IDRESPONSAVEL = responsavel.RESP_ID
JOIN reserva on principal.IDRESERVA = reserva.RES_ID
WHERE principal.PROJETO LIKE '%$q%'
PHP for table display:
<tr>
<td height="27"><?php echo $row_BUSCA['ID']; ?></td>
<td><?php echo $row_BUSCA['PROJETO']; ?></td>
<td><?php echo $row_BUSCA['DATA']; ?></td>
<td><?php echo $row_BUSCA['IDPRODUTO']; ?></td>
<td><?php echo $row_BUSCA['IDPRODUTO2']; ?></td>
<td><?php echo $row_BUSCA['IDPRODUTO3']; ?></td>
<td><?php echo $row_BUSCA['IDPRODUTO4']; ?></td>
<td><?php echo $row_BUSCA['IDRESPONSAVEL']; ?></td>
<td><?php echo $row_BUSCA['DESIGNADOR']; ?></td>
<td><?php echo $row_BUSCA['TAGS']; ?></td>
<td><?php echo $row_BUSCA['EQUIPAMENTO']; ?></td>
<td><?php echo $row_BUSCA['IDRESERVA']; ?></td>
<td><?php echo $row_BUSCA['ARQUIVO']; ?></td>
<td><?php echo $row_BUSCA['PROD_ID']; ?></td>
<td><?php echo $row_BUSCA['PROD_NOME']; ?></td>
<td><?php echo $row_BUSCA['PROD_NOME']; ?></td>
<td><?php echo $row_BUSCA['PROD_NOME']; ?></td>
<td><?php echo $row_BUSCA['PROD_NOME']; ?></td>
<td><?php echo $row_BUSCA['RESP_ID']; ?></td>
<td><?php echo $row_BUSCA['RESP_NOME']; ?></td>
<td><?php echo $row_BUSCA['RESPO_TEL']; ?></td>
<td><?php echo $row_BUSCA['RES_NOME']; ?></td>
</tr>
NOTE: It is very rudimentary.. later I will work on the details.
Grateful for any help.
Luciano.
@dherik is right. Can you show the definition of the tables? And easier to help when we see the query do by the table
– Justin Hanley