Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Pessoal beleza...Abaixo Segue Código de Categorias ( Inclusão / Exclusão / Alteração ), simples mais funcionando...rsItaum gostaria da ajuda de você´s para implementar para subcategorias ilimitadas....Postem por FAVOR!BANCO DE DADOS
CategoryID int(10) NOT NULL auto_increment,CategoryName varchar(255) NOT NULL default '',
conn.php
> <?php//enter your MySQL database host name, often it is not necessary to edit this line$db_host = "localhost";//enter your MySQL database username$db_username = "root";//enter your MySQL database password$db_password = "root";//enter your MySQL database name$db_name = "base_de_dados"; //////////////////////////////////////////////////////////// ////// do not edit below this line /////// /////////////////////////////////////////////////////////////connect to the database server$connection = mysql_connect($db_host, $db_username, $db_password) or die(mysql_error());//select database$db = mysql_select_db($db_name, $connection);session_start();$t = time();?>
category.php
> <?require_once("conn.php");if(!empty($_POST[newname])){ $q1 = "insert into class_categories set CategoryName = '$_POST[newname]'"; mysql_query($q1); if(mysql_error()) { echo "<br><center><font color=red face=verdana size=2><b>A categoria <font color=black>$_POST[newname]</font> já está sendo utilizada! <br>Selecione outra, por favor.</b></font></center>"; }}?><br><br><form method=post><table width=450 align=center><caption align=center><b>Criar nova categoria</b></caption><tr> <td align=right>Nome da categoria: </td> <td><input type=text name=newname size=45></td></tr><tr> <td> </td> <td><input type=submit name=s1 value=Criar class="sub1"></td></tr></table></form><?//get the category list$q1 = "select * from class_categories order by CategoryName";$r1 = mysql_query($q1) or die(mysql_error());if(mysql_num_rows($r1) > 0){ echo "<table width=400 align=center cellspacing=0>"; echo "<caption align=center><b>Categorias Existentes</b></caption>"; echo "<tr style=\"background-color:#FF9933; font-family:verdana; font-size:10; font-weight:bold; color:white\">"; echo "<td>Categorias</td>\n\t<td align=center width=100>Ação</td>\n</tr>\n"; $col = "white"; while($a1 = mysql_fetch_array($r1)) { if($col == "white") { $col = "#dddddd"; } else { $col = "white"; } echo "<tr bgcolor=$col>\n\t<td>$a1[CategoryName]</td>\n\t"; echo "<td align=center>\n\t\t<a href=\"edit_category.php?id=$a1[CategoryID]\" class=GreenLink>editar</a> | \n\t\t<a href=\"delete_category.php?id=$a1[CategoryID]\" class=RedLink>excluir</a>\n\t</td>\n</tr>\n\n"; } echo "</table>";}?>
edit_category.php
> <?require_once("conn.php");if(!empty($_POST[newname])){ $q1 = "update class_categories set CategoryName = '$_POST[newname]' where CategoryID = '$_GET[id]' "; mysql_query($q1); if(mysql_error()) { $error = "<br><center><font color=red face=verdana size=2><b>A categoria <font color=black>$_POST[newname]</font> já está sendo utilizada! <br>Por favor, selecione outro.</b></font></center>"; } else { header("location:category.php"); exit(); } }//get the category info$q1 = "select * from class_categories where CategoryID = '$_GET[id]' ";$r1 = mysql_query($q1) or die(mysql_error());$a1 = mysql_fetch_array($r1);?><br><?=$error?><br><form method=post><table width=450 align=center><caption align=center><b>Renomear categoria</b></caption><tr> <td align=right>Nome atual da categoria: </td> <td><b><?=$a1[CategoryName]?></b></td></tr><tr> <td align=right>Novo nome: </td> <td><input type=text name=newname size=45></td></tr><tr> <td> </td> <td><input type=submit name=s1 value=Mudar class="sub1"></td></tr></table></form>
delete_category.php
> <?require_once("conn.php");$q1 = "delete from class_categories where CategoryID = '$_GET[id]' ";mysql_query($q1) or die(mysql_error());header("location:category.php");?>
Pessoal Postem... vamos implementar esse código para Categorias Ilimitadas
Carregando comentários...