Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Dae galera! Estou desenvolvendo um sistema básico de controle de estoque para aprender alguns mecanismos do PHP e MYSQL.
Minha primeira dúvida é a seguinte: Tenho uma página "produtos_con.php" onde eu recebo todos os produtos cadastrado com código, nome e preço. Gostaria de saber como limitar a exibição para 15 itens onde possa avançar ou voltar a página.
A segunda dúvida é: Eu recebo os dados dos produtos por ordem alfabética, mas gostaria de poder clicando no titulo código ou no título preço, mudar a ordem da exibição para a escolhida clicando 1 vez em ordem crescente e se clicar de novo no mesmo título muda para ordem decrescente.
Será que é possível fazer tudo isso na mesma página, ou tenho que criar páginas separadas para cada operação?
Aqui está o código da página:
<?php
require_once("admin/restringir.php");
?>
<!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">](http://www.w3.org/1999/xhtml)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PRÓ ESTOQUE</title>
<link rel="stylesheet" type="text/css" href="includes/estilo.css" />
<script>function cor_tabela(id){
var cor1="#F2F2F2";
var cor2="#E0E0E0";
var x=document.getElementById(id).getElementsByTagName('tr');
for(i=0;i<x.length;i++)
x[i].style.backgroundColor=(i%2==0)?cor1:cor2;
}
</script>
</head>
<body>
<div id="corpo" align="center">
<?php
include "includes/topo.php";
include "includes/menu.php";
?><BR>
<table width="700" border="1" cellpadding="0" cellspacing="0" align="center">
<tr>
<td align="right">
BUSCAR PRODUTO:
</td>
<td align="left"><form id="form1" name="form1" method="post" action="exibir_busca.php">
<label>
<input type="text" name="campo_busca" id="campo_busca" />
</label>
<label>
<input type="submit" name="button" id="button" value="Efetuar Busca" />
</label>
</form></td>
</tr>
</table>
<table width="700" border="1" cellpadding="0" cellspacing="0" align="center" style="margin-top:50px;">
<tr><td height="30" colspan="4" align="center" background="imagens/fundotitover.jpg" style="border-top: solid 1px #000; border-right: solid 1px #000; border-left: solid 1px #000;"><b>CONSULTA DE PRODUTOS<br /></b></td></tr>
<tr style="background-image:url(imagens/bgcampo.jpg); height:30px;">
<td width="100" align="center" style="border-bottom: solid 1px #000000; border-left: solid 1px #000000;">CÓDIGO</td>
<td width="450" align="center" style="border-bottom: solid 1px #000000;">NOME</td>
<td width="150" align="center" style="border-bottom: solid 1px #000000; border-right: solid 1px #000000;">PREÇO</td>
</tr>
</table>
<table width="700" id="tb1" cellpadding="0" cellspacing="0" align="center">
<?php
require_once("includes/conect_mysql.php");
conecta_BD();
$sql = "SELECT id_produtos, nome_produtos, preco_produtos FROM produtos order by nome_produtos";
$linha = query($sql);
while ($dados = le_linha($linha))
{
echo '<tr>';
echo '<td width="100" align="center" style="border-bottom: solid 1px #000000; border-right: solid 1px #000000; border-left: solid 1px #000000;"><a href="produtos_cad.php?id='.$dados[id_produtos].'">'.$dados[id_produtos].'</a></td>';
echo '<td width="450" align="center" style="border-bottom: solid 1px #000000; border-right: solid 1px #000000;"><a href="produtos_cad.php?id='.$dados[id_produtos].'">'.$dados[nome_produtos].'</a></td>';
echo '<td width="150" align="center" style="border-bottom: solid 1px #000000; border-right: solid 1px #000000;">R$ <a href="produtos_cad.php?id='.$dados[id_produtos].'">'.number_format($dados[preco_produtos], 2, ',', '.').'</a></td>';
echo '</tr>';
}
?>
</table>
<script>
cor_tabela("tb1");
</script><BR>
</div>
</body>
</html>Carregando comentários...