List only data of the same id

0

Well, guys, after a long time of banging my head with a certain problem I can solve it in a certain way (gambiarra) but now I need to know how to list data from my database that is of the same id, I add several products in a certain sale and I wanted to list those products only from that sale, I tried to use the while plus it returns me a repeated list of values from my entire table

My code:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script>

        function alguma(e){
            if(!confirm("Deseja realmente excluir este registro?"))
                cancelOperation(event);
        }
        function cancelOperation(e){
            var evt = e || window.event;
            if(evt.preventDefault())
                evt.preventDefault();
            else
                evt.returnValue = false;
        }
    </script>
</head>

<?php
include("banco.php");
echo'<link rel="stylesheet" type="text/css" href="css/estilo.css">';
echo'<link rel="stylesheet" type="text/css" href="css/bootstrap.css">';
 include("banco.php");

   $id = $_GET["id"];

        $sql = mysql_query("select * from venda where id_venda='$id'");

        $exibe = mysql_fetch_assoc($sql);

        $perfil=mysql_query("SELECT * FROM venda WHERE id_venda='$id'");

        $dados=list($id_venda,$venda,$data,$placa,$km)=mysql_fetch_row($perfil);

$produtos = "SELECT * FROM produtos WHERE id_produto=". $dados[5];
$query = mysql_query($produtos);
$b=mysql_fetch_array($query);
#$id = $b ['id'];
$produtos = $b ['produtos'];


$servicos = "SELECT * FROM servicos WHERE id_servico=". $dados[6];
$query = mysql_query($servicos);
$c=mysql_fetch_array($query);
#$id = $b ['id'];
$servicos = $c ['servicos'];


?>
<label for="nome" style="color: #000"><strong>ID DA VENDA :</strong> </label>
<input type="text" readonly="true" name="id" style="width: 170px" value="<?php echo $dados[0]; ?>">

<div id="camp5">
<label for="nome"readonly="true" style="color: #000"><strong>Nº DA VENDA:</strong> </label>
<input type="text" name="id" readonly="true" style="width: 170px" value="<?php echo $dados[1]; ?>">
</div>

<div id="camp1">
<label for="nome" style="color: #000"><strong>DATA :</strong> </label>
<input type="text" name="id" readonly="true" style="width: 170px" value="<?php echo $dados[2]; ?>">
</div>

<div id="camp6">
<label for="nome" style="color: #000"><strong>PLACA :</strong> </label>
    <input type="text" name="id" readonly="true" style="width: 170px" value="<?php echo $dados[3]; ?>">
</div>

<div id="camp2">
<label for="nome" style="color: #000"><strong>KM :</strong> </label>
<input type="text" name="id" readonly="true" style="width: 170px" value="<?php echo $dados[4]; ?>">

</div>

<br><br>
<div id="adicionar">
    <a href="adcproduto.php" class="btn btn-info    ">ADICIONAR MAIS PRODUTOS&nbsp;&nbsp;<img src="img/add-icon.png"/></a><br><br>
</div>

<label for="nome" style="color: #000"><strong>PRODUTO :</strong> </label>
<input type="text" name="id" style="width: 450px" readonly="true"  value="<?php echo $produtos; ?>"><br>

<?php
$selbanco = "SELECT * FROM pedido";
$querybanco = mysql_query($selbanco);

$sql1 = mysql_query("select * from pedido where id_venda='$id'");

$exibe1 = mysql_fetch_assoc($sql1);

$perfil1=mysql_query("SELECT * FROM pedido WHERE id_venda='$id'");

$lista=list($id, $produtos , $idvenda)=mysql_fetch_row($perfil1);


?>

<input type="text" name="id" style="width: 450px" readonly="true"  value="<?php echo $lista[1]; ?>"><br>


</body>
</html>

In this part I make to appear the products but only the first appears, and when I tried with the while it returns me all the data of the table, does anyone know how I can do this? :

<?php
$selbanco = "SELECT * FROM pedido";
$querybanco = mysql_query($selbanco);

$sql1 = mysql_query("select * from pedido where id_venda='$id'");

$exibe1 = mysql_fetch_assoc($sql1);

$perfil1=mysql_query("SELECT * FROM pedido WHERE id_venda='$id'");

$lista=list($id, $produtos , $idvenda)=mysql_fetch_row($perfil1);


?>

<input type="text" name="id" style="width: 450px" readonly="true"  value="<?php echo $lista[1]; ?>"><br>
    
asked by anonymous 24.12.2015 / 13:19

1 answer

0

Look, there are 2 SQLs in the same table in your example, in my view there are two things, either you use only one table to save the sale or you should have the table name in the second SQL wrong. By way of example I would store this type of transaction in at least two tables:

tab_vendas
tab_vendas_itens

The sales table stores information specific to the order (Total Value, CustomerID, Fiscal Note, etc.), and to items (Product Code, Unit Value, Sales Value, Discount Item, Quantity and etc.)

This is an example of a structure to store the information, but suppose you are using only one table, in the first SQL you must specify only fields that do not contain single data as Sequential ID of the table and not "*", there you uses DISTINCT to avoid duplicate data.

    
24.12.2015 / 15:06