Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Boa noite,
Pessoal, coloquei este código abaixo para ordenar os produtos que estão com a quantidade abaixo da atual, porem o mesmo não esta me mostrando o resultado correto, o que pode estar de errado no mesmo?
<?php require_once('../Connections/Connection.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_Connection, $Connection);
$query_Lista_Est_Minimo = "SELECT * FROM estoque WHERE qtd_minima < qtd_atual ORDER BY descricao ASC";
$Lista_Est_Minimo = mysql_query($query_Lista_Est_Minimo, $Connection) or die(mysql_error());
$row_Lista_Est_Minimo = mysql_fetch_assoc($Lista_Est_Minimo);
$totalRows_Lista_Est_Minimo = mysql_num_rows($Lista_Est_Minimo);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<p align="center"><strong>Estoque Mínimo</strong></p>
<table width="100%" border="0">
<tr>
<td><p><strong>Código</strong></p></td>
<td><strong>Código de Barras</strong></td>
<td><strong>Descrição</strong></td>
<td><strong>Medida</strong></td>
<td><strong>Preço R$</strong></td>
<td><strong>Qtd. Atual</strong></td>
<td><strong>Qtd. Mínima</strong></td>
<td colspan="2"><strong>Opções</strong></td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Lista_Est_Minimo['codigo_produto']; ?></td>
<td><?php echo $row_Lista_Est_Minimo['codigo_barras']; ?></td>
<td><?php echo $row_Lista_Est_Minimo['descricao']; ?></td>
<td><?php echo $row_Lista_Est_Minimo['medida']; ?></td>
<td><?php echo $row_Lista_Est_Minimo['preco_venda']; ?></td>
<td><?php echo $row_Lista_Est_Minimo['qtd_atual']; ?></td>
<td><?php echo $row_Lista_Est_Minimo['qtd_minima']; ?></td>
<td><a href="../Alt_estoque.php?codigo_produto=<?php echo $row_Lista_Est_Minimo['codigo_produto']; ?>"><img src="../Imagens/Editar.png" width="20" height="20" /></a></td>
<td><a href="../Apaga_estoque.php?codigo_produto=<?php echo $row_Lista_Est_Minimo['codigo_produto']; ?>"><img src="../Imagens/delete.gif" width="20" height="20" /></a></td>
</tr>
<?php } while ($row_Lista_Est_Minimo = mysql_fetch_assoc($Lista_Est_Minimo)); ?>
</table>
<p align="center"><!-- Função Imprimir //-->
<a href="javascript:;" onclick="window.print();return false"><img src="../Imagens/print.png" title="Imprimir" /></a></p>
</body>
</html>
<?php
mysql_free_result($Lista_Est_Minimo);
?>Mas este é um problema, pois preciso dos itens em ordem alfabética.
o mesmo não esta me mostrando o resultado correto
explique melhor o ordenamento desejado e qual erro acontece
Fernando C,
Preciso que o código seja ordenado por descrição. Preciso também que o mesmo me mostre os produtos que estão com sua quantidade mínima atingida.
Exemplo:
Estoque Ideal: 10
Estoque atual: 8
Este produto atingiu o minimo ou seja ele tem que aparecer na listagem.
ok.. é q você postou erro no "ordenamento"..
mas se entendi bem, tente inverter as colunas na sql:
SELECT * FROM estoque WHERE qtd_atual < qtd_minima ORDER BY descricao ASC
obs: as colunas "qtd_atual" e "qtd_minima" defini como "int", ok?
qqer coisa, retorne c/ o erro.
Deu certo. Obrigado pela ajuda.
O ORDER BY define o ordenamento, no caso DESCRICAO.
Troque o ordenamento se for o caso.