3
I found a tutorial talking about JOINS and implanted in the survey for sales made.
But it was almost all right, only at the time of the search for the sales code, instead of bringing me only the result referring to the code consulted, it brings me the other code and repeated, and several times. In addition to looping around.
I am publishing below the code used so that friends can take a look, and tell me where I am missing or if something is missing.
<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>
Try using a Outer Join.
– ptkato
I’ll give it a try, Patrick, and if it works out, I’ll publish the results, okay? But I edited my problem with a solution on the local server, but this presenting me problem on the Hosting server. If you can give an analysis of why he keeps giving direct loop thank you. But I will try with OUTER JOIN, who knows can be this.
– Murilo Cabral