Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
"-Aviso desde já que é um algoritmo bem simples." Galerinha, criei uma função php que faça trabalhe com o valor de uma variável, $acao, que será modificada via link/barra de endereço e tal...
no caso, se $acao = "(vazio)" --> então aparecerá uma lista
mas, se caso ela for de algum valor ---> então aparecerá um <form>.
Mas acontece que a variável não está mudando quando faço dou o comando pelo navegador, por exemplo= .../categoria.php?acao=Algumvalor
Sou novo nessa área, aqui está o código do que falei: [Agradeço desde já qualquer ajuda :D ]
e mais abaixo o código completo p uma melhor analise.
- <?php if( $acao != "") {
- $sql = mysql_query("SELECT * from categorias Where id_categoria = $id "); ?>
-
- <form name="form1" method="post" action="<?php echo $PHP_SELF ?>">
- <table align="center" border = "1" width="450px">
- <tr>
- <td><b>Categoria:</b></td>
- <td><input name="txt_categoria" value="<?php echo @mysql_result($sql,0,categoria); ?>"></td>
- </tr>
- <tr>
- <td colspan="2"><input name="submit" type="submit" value="OK"></td>
- </tr>
- </table>
- </form>
-
-
- <table align="center" border = "1" width="450px">
- <tr>
- <td><b>Categorias:</b></td>
- <td width="12%" colspan="2"><b>Ações:</b></td>
- </tr>
-
- <?php
- $sql = mysql_query("select * from categorias");
- while ($coluna = mysql_fetch_array($sql)) { ?>
-
- <tr>
- <td><?php echo $coluna[categoria]?></td>
- <td><a href="?acao=Alterar&id= <?php echo $coluna[id_categoria]; ?>"><img src="img/edit.gif" width="20" height="20"/></a></td>
- <td><a href="?Excluir=ok?id=<?php echo $coluna[id_categoria]; ?>"><img src="img/del.gif" width="20" height="20"/></a></td>
- </tr>
- <?php } ?>
código completo:
-
<?php include "config.php";
?><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>Area ADM</title>
</head>
<body>
<table width="750" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2"><?php include "cabecalho.php"; ?></td>
</tr>
<tr>
<td width="49" height="113"><?php include "menu.php"; ?></td>
<td >
<?php if( $acao != "") {
$sql = mysql_query("SELECT * from categorias Where id_categoria = $id "); ?>
<form name="form1" method="post" action="<?php echo $PHP_SELF ?>">
<table align="center" border = "1" width="450px">
<tr>
<td><b>Categoria:</b></td>
<td><input name="txt_categoria" value="<?php echo @mysql_result($sql,0,categoria); ?>"></td>
</tr>
<tr>
<td colspan="2"><input name="submit" type="submit" value="OK"></td>
</tr>
</table>
</form>
<?php }else{ ?>
<table align="center" border = "1" width="450px">
<tr>
<td><b>Categorias:</b></td>
<td width="12%" colspan="2"><b>Ações:</b></td>
</tr>
<?php
$sql = mysql_query("select * from categorias");
while ($coluna = mysql_fetch_array($sql)) { ?>
<tr>
<td><?php echo $coluna[categoria]?></td>
<td><a href="?acao=Alterar&id= <?php echo $coluna[id_categoria]; ?>"><img src="img/edit.gif" width="20" height="20"/></a></td>
<td><a href="?Excluir=ok?id=<?php echo $coluna[id_categoria]; ?>"><img src="img/del.gif" width="20" height="20"/></a></td>
</tr>
<?php } ?>
<tr>
<td bgcolor="#cccccc" ></td>
<td width="12%" colspan="2"><a href="?acao=Inserir"><img src="img/add.gif" width="50" height="20"/></a></td>
</tr>
</table>
<?php } ?> </td>
</tr>
<tr>
<td height="140" colspan="2"> </td>
</tr>
</table>
</body>
</html>Carregando comentários...