Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Skrypt kategori:
wozniak
post
Post #1





Grupa: Zarejestrowani
Postów: 278
Pomógł: 0
Dołączył: 21.11.2003

Ostrzeżenie: (0%)
-----


Witam napisałem skrypt kategori i nie wiem jak zrobic ze jak sie usunie główna kategorie to usuwaja sie jej wszystkie podkategorie?
Skrypt:
  1. <? 
  2.  
  3. function wszystkie(){ ?> <table border=\"0\" width=\"442\">
  4.  <?php  
  5. {  
  6.  $zapytanie = sql(&#092;"SELECT * FROM kategorie WHERE nalezy='0'\"); 
  7.  while ($rekord = mysql_fetch_array($zapytanie)) 
  8. {  
  9.  $id = $rekord['id'];
  10.  $nazwa = $rekord['nazwa'];
  11.  $nazlezy = $rekord['nazlezy'];
  12.  $foto = $rekord['foto'];
  13.  
  14.  
  15. echo&#092;" <tr>
  16. <td height=&#092;"21\" width=\"19\"><img src=\"images/folder.gif\"></td>
  17. <td height=&#092;"21\" width=\"358\"><a href=\"index.php?wlacz=kategorie&co=kat&id=$id\">$nazwa</a></td>
  18. <td height=&#092;"21\" width=\"16\"><img src=\"images/edytuj.png\"></td>
  19. <td height=&#092;"21\" width=\"16\"><a href=\"index.php?wlacz=kategorie&co=usun_kat&id=$id\"><img border=\"0\" src=\"images/usun.png\"></a></td>
  20. </tr>&#092;";
  21.  
  22.  
  23. }
  24. } print(&#092;"</table>\");
  25. echo&#092;"<table><tr><td><BR><a href=\"index.php?wlacz=kategorie&co=Dodaj_kat\">dodaj kategorie</a></td></tr></table>\";
  26. }
  27.  
  28.  
  29. function kat($id){ ?> <table border=\"0\" width=\"442\" height=\"84\">
  30.  <?php  
  31. {  
  32.  $zapytanie = sql(&#092;"SELECT * FROM kategorie WHERE nalezy='$id'\"); 
  33.  while ($rekord = mysql_fetch_array($zapytanie)) 
  34. {  
  35.  $id = $rekord['id'];
  36.  $nazwa = $rekord['nazwa'];
  37.  $nazlezy = $rekord['nazlezy'];
  38.  $foto = $rekord['foto'];
  39.  
  40.  
  41. echo&#092;" <tr>
  42. <td height=&#092;"21\" width=\"19\"><img src=\"images/folder.gif\"></td>
  43. <td height=&#092;"21\" width=\"358\"><a href=\"index.php?wlacz=kategorie&co=kat&id=$id\">$nazwa</a></td>
  44. <td height=&#092;"21\" width=\"16\"><img src=\"images/edytuj.png\"></td>
  45. <td height=&#092;"21\" width=\"16\"><a href=\"index.php?wlacz=kategorie&co=usun_kat&id=$id\"><img border=\"0\" src=\"images/usun.png\"></a></td>
  46. </tr>&#092;";
  47.  
  48.  
  49.  
  50. }  
  51. } 
  52.  
  53.  
  54. if (isset($id)) { $der=&#092;"&id=$id\"; } echo\"<BR><a href=\"index.php?wlacz=kategorie&co=Dodaj_kat$der\">dodaj kategorie</a>\";
  55. print(&#092;"</table>\");
  56. }
  57.  function Dodaj_kat($id){ 
  58.  
  59.  if (isset($id)) { $der=&#092;"&id=$id\"; }
  60.  echo&#092;"<form method=\"post\" enctype=\"multipart/form-data\" action=\"index.php?wlacz=kategorie&co=dodaj_kat_tak$der\">
  61. <p>Nazwa: <input type=&#092;"text\" name=\"nazwa\" size=\"20\"><br>
  62. <br>
  63. <input type=&#092;"submit\" value=\"Dodaj\"></p>
  64. </form>&#092;";
  65.  } 
  66. function dodaj_kat_tak($id,$nazwa){
  67.  
  68.  if (!isset($id)) {$id=&#092;"0\";}
  69. $query = sql(&#092;"INSERT INTO kategorie SET nalezy='$id', nazwa='$nazwa', foto='$foto';\"); 
  70. print(&#092;" Kategoria zostala Dodana\");
  71. print(&#092;"<BR> <a href=\"index.php?wlacz=kategorie\">Wroc</a>\");  
  72.  
  73. }
  74. function usun_kat($id){
  75.  
  76. {  
  77.  $zapytanie = sql(&#092;"SELECT * FROM kategorie WHERE id='$id'\"); 
  78.  while ($rekord = mysql_fetch_array($zapytanie)) 
  79. {  
  80.  
  81.  $nazwa = $rekord['nazwa'];
  82.  $nazlezy = $rekord['nazlezy'];
  83.  $foto = $rekord['foto'];
  84. echo&#092;"Napewno chcesz usunac kategorie : <i>$nazwa</i>?<BR><a href=\"index.php?wlacz=kategorie&co=usun_kat_tak&id=$id\">TAK</a> | <a href=\"index.php\">NIE</a>\";
  85. }
  86.  
  87.  }
  88.  } 
  89.  function usun_kat_tak($id) {
  90. $zapytanie = sql(&#092;"DELETE FROM kategorie WHERE id='$id';\"); 
  91. print(&#092;" Kategoria zostala usunieta\");
  92. print(&#092;"<BR> <a href=\"index.php?wlacz=kategorie\">Wroc</a>\");
  93.  } 
  94.  switch ($co) {
  95.  
  96. default:
  97. wszystkie();
  98. break;
  99.  
  100. case &#092;"usun_kat\":
  101. usun_kat($id);
  102. break;
  103.  
  104. case &#092;"usun_kat_tak\":
  105. usun_kat_tak($id);
  106. break;
  107.  
  108. case &#092;"dodaj\":
  109. dodaj();
  110. break;
  111.  
  112. case &#092;"zapisz\":
  113. zapisz($nazwa);
  114. break;
  115.  
  116. case &#092;"kat\":
  117. kat($id);
  118. break;
  119.  
  120. case &#092;"Dodaj_kat\":
  121.  dodaj_kat($id);
  122. break;
  123.  
  124. case &#092;"dodaj_kat_tak\":
  125.  dodaj_kat_tak($id,$nazwa);
  126. break;
  127. }
  128. ?>


My sql:
  1. CREATE TABLE `kategorie` (
  2. `id` int(255) NOT NULL AUTO_INCREMENT,
  3. `nazwa` varchar(255) NOT NULL DEFAULT '',
  4. `foto` varchar(255) NOT NULL DEFAULT '',
  5. `nalezy` varchar(255) NOT NULL DEFAULT '0',
  6. PRIMARY KEY (`id`)
  7. ) TYPE=MyISAM PACK_KEYS=0 AUTO_INCREMENT=8 ;
  8.  
  9. --
  10. -- Zrzut danych tabeli `kategorie`
  11. --
  12.  
  13. INSERT
  14. INTO `kategorie` VALUES (1, 'Akcesoria', '', '0');
  15. INSERT
  16. INTO `kategorie` VALUES (2, 'Chłodzenie', '', '0');
  17. INSERT
  18. INTO `kategorie` VALUES (3, 'Chłodzenie H2O', '', '0');
  19. INSERT
  20. INTO `kategorie` VALUES (4, 'Obudowy', '', '0');
  21. INSERT
  22. INTO `kategorie` VALUES (5, 'Okablowanie', '', '0');
  23. INSERT
  24. INTO `kategorie` VALUES (6, 'Okna', '', '0');
  25. INSERT
  26. INTO `kategorie` VALUES (7, 'Oświetlenie', '', '0');
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 559
Pomógł: 6315
Dołączył: 27.12.2004




glowna i podrzedne:
"delete from kategorie where id=$id or nalezy=$id"


Cytat
CREATE TABLE `kategorie` (
`id` int(255) NOT NULL auto_increment,
`nazwa` varchar(255) NOT NULL default '',
`foto` varchar(255) NOT NULL default '',
`nalezy` varchar(255) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM

Coś tu chyba namieszales:
1) id int(255) duzo cos. wystarczy 11
2) nalezy varchar(255). powinno być tez int (11). domyslam się ze nalezy to odnosi sie do id, wiec musi byc ten sam typ
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 12.10.2025 - 15:49