Eu encontrei um tutorial falando sobre JOINS e implantei na pesquisa pelas vendas realizadas.
Mas deu quase tudo certo, só que na hora da busca pelo código de venda, ao invés de me trazer somente o resultado referente ao código consultado, ele me traz o outro código e repetidos, e por varias vezes. Além de ficar dando loop.
Estou publicando abaixo o código usado para que os amigos possam dar uma analisada, e me dizer onde estou errando ou se falta algo.
<div align="left" style=" padding:2px; width:315px; height:auto; float:left;">
<label>Entre com o código da Venda</label>
<form action="prod_consulta_venda.php" enctype="multipart/form-data" name="busca" method="post">
<input size="6" type="text" value="" name="buscar"/>
<input type="submit" name="busca" value="Buscar Venda"/>
</form>
</div>
</div>
<div align="left" style=" padding:2px; width:1000px; height:auto; border-top:solid 2px; float:left;">
<br />
<?php
include 'conexao.php';
$buscar = $_POST['buscar'];
$sql_listar = mysql_query("SELECT VENDA.codvenda, VENDA.codcliente, VENDA.datavenda, VENDA.total, ITEMVENDA.codproduto, ITEMVENDA.quant, ITEMVENDA.preco, CLIENTE.nome, CLIENTE.endereco, CLIENTE.bairro, CLIENTE.cidade, CLIENTE.estado, CLIENTE.cep FROM VENDA, ITEMVENDA, CLIENTE WHERE VENDA.codcliente = ITEMVENDA.codcliente = CLIENTE.codcliente LIKE '%$buscar%'");
$total_registros = mysql_num_rows($sql_listar);
if(mysql_num_rows($sql_listar) <= 0){
echo '<script type="text/javascript">
alert("Desculpe! Nenhuma Venda foi encontrada com esse código!");
window.location.href = "prod_consulta_venda.php";
</script>';
}else{
while($res = mysql_fetch_array($sql_listar)){
$conteudotabela1 .= '<tr style="color:#090;">
<td align="center">'.$res['codvenda'].'</td>
<td align="center">'.$res['codcliente'].'</td>
<td align="center">'.$res['datavenda'].'</td>
<td align="center">'.$res['total'].'</td>
<td align="center">'.$res['codproduto'].'</td>
<td align="center">'.$res['quant'].'</td>
<td align="center">'.$res['preco'].'</td>
<td align="center">'.$res['nome'].'</td>
<td align="center">'.$res['endereco'].'</td>
<td align="center">'.$res['bairro'].'</td>
<td align="center">'.$res['cidade'].'</td>
<td align="center">'.$res['estado'].'</td>
<td align="center">'.$res['cep'].'</td>
</tr>';
}}
?>
<table class="tbllista" style="width: 15%">
<thead>
<tr align="center">
<th style="width: 5%"></th>
<th style="width: 5%">
</tr>
</thead>
</table>
<table class="tbllista" style="width: 100%">
<thead>
<tr align="center">
<th align="center">Cód. Venda</th>
<th align="center">Cód. Cliente</th>
<th align="center">Data da Venda</th>
<th align="center">Total da Venda</th>
<th align="center">Cód. Produto</th>
<th align="center">Quantidade</th>
<th align="center">Preço Unitário</th>
<th align="center">Nome</th>
<th align="center">Endereço</th>
<th align="center">Bairro</th>
<th align="center">Cidade</th>
<th align="center">Estado</th>
<th align="center">Cep</th>
</tr>
</thead>
<tbody>
<?php echo $conteudotabela1; ?>
</tbody>