2
Guys, I’m looking at two tables with INNER JOIN
thus:
if (! $db->Query("select * from cad_produto inner join cad_variacoes on cad_variacoes.id_produto = cad_produto.id"))
$db->Kill();
while (! $db->EndOfSeek()) {
$row = $db->Row();
$titulo = $row->titulo; //TABELA 1
$valor = $row->valor; //TABELA 2
$quantidade = $row->quantidade; //TABELA 2
$id = $row->id_produto; //TABELA 2
}
TABLE 1:
+----------------------------+
| PRODUTO |
+------------+---------------+
| ID | TITULO |
| 1 | arroz |
| | |
| | |
| | |
+------------+---------------+
TABLE 2:
+---------------------------+
| ATRIBUTO 1 |
+------------+--------------+
| ID_PRODUTO | VALOR |
| 1 | 10 |
| | |
| | |
| | |
+------------+--------------+
+---------------------------+
| ATRIBUTO 2 |
+------------+--------------+
| ID_PRODUTO | QUANTIDADE |
| 1 | 5 |
| 1 | 6 |
| | |
| | |
+------------+--------------+
I need that at the time of loop appear only the loop AS A REFERENCE TO THE NUMBER OF ROWS IN TABLE 1 AND NOT IN TABLE 2, but it’s happening the other way. It’s coming like this:
ID(dado da tabela 2) TITULO VALOR QUANTIDADE
1 ARROZ 10 5
ID(dado da tabela 2) TITULO VALOR QUANTIDADE
1 ARROZ 10 6
I need you to come only 1 row and with your respective attributes.
UPDATE
It was supposed to look like this, taking a random value from table 2:
ID(dado da tabela 2) TITULO VALOR QUANTIDADE
1 ARROZ 10 5
I can not put LIMIT 1, because when there are two products will be like this:
ID(dado da tabela 2) TITULO VALOR QUANTIDADE
1 ARROZ 10 5
ID(dado da tabela 2) TITULO VALOR QUANTIDADE
2 FEIJAO 11 1
Puts the title outside the
while
.– Diego Souza
But when there are two rows in table 1, you will have two products consulted, two titles, one in each row.
– Lollipop
Oh understood. It was bad. But in this case you want it to appear as ? Can you reproduce in your post ? Is it to add up the amount ? Why just like that to appear on one line.
sum(quantidade)
andgroup by id
– Diego Souza
@Diegosouza, I will edit...see the question change below.
– Lollipop
It’s a little complicated to understand your logic. You can’t put
LIMIT 1
if it doesn’t happen what you’ve shown there. You want a random row to appear with a table 2 value of only 1 product ?– Diego Souza
This, but by product, summarizing the loop is based on table 1 with the data in table 2.
– Lollipop
Have you tried using LEFT JOIN instead of INNER JOIN?
– Igor Silva
already, Igor silva ...........
– Lollipop