0
I have the following problem: I have a table called pedido
. In this table I get data from two other tables:
I would like to make a list only of products that have the same id_venda
. In my code only appears the first item added with equal id:
<?php
$perfil1=mysql_query("SELECT * FROM pedido WHERE id_venda='$id'");
$lista=list($id, $produtosb , $idvenda)=mysql_fetch_row($perfil1);
$prod = "SELECT * FROM produtos WHERE id_produto=". $lista[1];
$query = mysql_query($prod);
$b=mysql_fetch_array($query);
$prod = $b ['produtos'];
?>
<input type="text" name="id" style="width: 450px" readonly="true" value="<?php echo $prod; ?>"><br>
I tried using Loop while, but it returns all table data. Which repeat loop should I use?
select * from pedidos inner join produtos on produtos = id_produto where id_venda= $id
Just pick the result and list using while.– user28595
If I were you I would use much more practical and safe PDO to work with database. This mysql_* function has become obsolete, since php 7 it will no longer exist!
– Romario Pires