3
I’m having a hard time showing the results of select
the way I want it. I’ll explain first what I have and then what I want, I have two tables in the database:
Product type: Product type, Product type and Brand:
id_product_brand and name_name.
I did the select
uniting the two tables to show me the result of the two:
<select name="carne">
<option value="vazio">
</option>
<?php
$sql = "(select tipo_produto from produto_tipo)
union (select nome_marca from produto_marca)";
$result = mysqli_query($conexao, $sql);
while($linha = mysqli_fetch_assoc($result)){ ?>
<option value=" <?php echo $linha['tipo_produto'].$linha['nome_marca']; ?> ">
<?php echo utf8_decode($linha['tipo_produto'].$linha['nome_marca']); ?>
</option>
<?php } ?>
</select>
So far so good, but it is not showing the concatenated result. It is showing so:
arroz
tio jõao
urbano
I need you to show it like this:
arroz tio joão
arroz urbano
The result of the first part (arroz
) comes from a table and the result of the second part (tio joao
) comes from the second table.
You want to change only the text that appears to the user or the value as well?
– Victor Eyer
only the output text
– Julia Campos
It happens because you’re doing it
union select
. Usejoin
. Not answered because it is without information about the relationship between the tables. Post the structure of both tables.– Daniel Omine
As far as I searched with Join I would need something that connects the two tables, and they are totally independent
– Julia Campos
Then you have nothing to do. rsrs.. How will you know that brand A, B or C belongs to product X or product Y? You have to have something that relates them, right. rsrsr
– Daniel Omine
If you are independent do a cross Join... but this can get a bit giant :)
– gmsantos
Put the structure of the two tables and the result you expect them to bring. Just one detail
UNION
is not used like this, it joins two "equal" tables but will be different lines.– Guilherme Nascimento