Fórum ListBox, não puxa do banco. #431671
29/12/2012
0
<?php
include ("conexao.php");
$acao = @$_GET["acao"];
$id = @$_GET["id"];
if ($acao != "")
{
$sql = "SELECT c.*, s.* FROM categoria c, subcategoria s WHERE c.id_categoria = s.id_categoria and id_subcategoria = '$id' ";
$qry = mysql_query($sql);
$linha = mysql_fetch_array($qry);
$subcategoria = $linha[subcategoria];
$id_categoria = $linha[id_categoria];
}
?>
<!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=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center">Cadastro de Categorias </div></td>
</tr>
<tr>
<td><form id="form1" name="form1" method="post" action="op_subcategoria.php">
<table width="314" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>Categoria</td>
<td><label>
<select name="id_categoria" id="id_categoria">
<option>Selecione uma categoria</option>
<?php
$sql = "SELECT * FROM categoria ORDE BY categoria";
$qry = mysql_query($sql);
while (@$linha = mysql_fetch_array($qry)){
$valor = $linha[id_categoria];
if ($id_categoria = $valor)
{
$selecionado = "selected";
}
else
{
$selecionado ="";
}
echo "<option value = \"$valor\" $selecionado > $linha[categoria] </option>";
}
?>
</select>
</label></td>
</tr>
<tr>
<td>SubCategoria</td>
<td width="211"><input name="txt_subcategoria" type="text" id="txt_subcategoria" value="<?php echo @$subcategoria; ?>" size="35" /></td>
</tr>
<tr>
<td colspan="2"><label>
<div align="center">
<input type="submit" name="Submit" value="<?php if($acao != ""){echo $acao;}else {echo "Inserir";}?>" />
<label>
<input name="acao" type="hidden" id="acao" value="<?php if($acao != ""){echo $acao;}else {echo "Inserir";}?>" />
</label>
<input name="id" type="hidden" id="id" value="<?php echo $id; ?>" />
<input name="id_categoria" type="hidden" id="id_categoria" value="<?php echo @$id_categoria; ?>" />
</div>
</label></td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</body>
</html>
Marcio Araujo
Curtir tópico
+ 0Posts
01/01/2013
Marcio Araujo
Gostei + 0
02/01/2013
Diego Melo
Qual o erro que aparece?
Olha não sei se você copiou direto do seu IDE, mas na parte abaixo, veja:
?php
$sql = "SELECT * FROM categoria ORDE BY categoria";
Está com erro de ORDE, ao inves de ORDER.
Uma boa prática é você testar todas as suas querys no phpmyadmin, pra ver se funciona, depois passar para o PHP.
Abraços.
Gostei + 0
04/01/2013
Marcio Araujo
Gostei + 0
05/01/2013
Marcio Araujo
Gostei + 0
05/01/2013
Diego Melo
Forte Abraço.
Gostei + 0
07/01/2013
Marcio Araujo
me salvou!!! hehehehehehe
vlw!!!
Gostei + 0
30/07/2013
José
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)