Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php][mysql] Kolejność bloków menu
Lee
post
Post #1





Grupa: Zarejestrowani
Postów: 319
Pomógł: 0
Dołączył: 11.04.2006
Skąd: Chojnów

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


Mam moduł bloków menu i gdy jedynie je przesuwam wszystko jest ok, ale gdy skasuje jakiś np. ze środka to już wszystko się rozwala :/

Tak przesuwam blok w górę (w doł pdobonie)
  1. <?php
  2. public function Up($id) {
  3. global $tbl_menu;
  4. $this -> query = mysql_query("SELECT * FROM $tbl_menu WHERE id='$id' LIMIT 1");
  5. while ($this -> result = mysql_fetch_assoc($this -> query)) {
  6. $up = $this -> result['order'];
  7. $position = $this -> result['position'];
  8. }
  9. $order = $up - 1;
  10. $this -> query = mysql_query("SELECT * FROM $tbl_menu WHERE `order`='$order' AND `position`='$position' LIMIT 1");
  11. while ($this -> result = mysql_fetch_assoc($this -> query)) {
  12. $down = $this -> result['order'];
  13. $id_down = $this -> result['id'];
  14. }
  15. $this -> query = mysql_query("UPDATE $tbl_menu SET `order`='$down' WHERE id='$id' LIMIT 1");
  16. $this -> query = mysql_query("UPDATE $tbl_menu SET `order`='$up' WHERE id='$id_down' LIMIT 1");
  17. header ('Location: admin.php?mod=menu');
  18. }
  19. ?>


a tak kasuję blok
  1. <?php
  2. public function Delete($id) {
  3. global $tbl_menu;
  4. echo 'Czy na pewno chcesz usunąć to menu ? (<a href="admin.php?mod=menu&act=delete&confirm=yes&id='.$id.'">Tak</a> | <a href="admin.php?mod=menu">Nie</a>)<br />';
  5. if ($_GET['confirm'] == 'yes') {
  6. @$this -> query = mysql_query("DELETE FROM $tbl_menu WHERE id='$id' LIMIT 1") or die (_MYSQL_ERROR_3 .''. mysql_error());
  7. echo 'Menu zostało usunięte ! <a href="admin.php?mod=menu">Powrót</a>';
  8. }
  9. }
  10. ?>

co powinienem zmienić/dodać ? próbowałem po skasowaniu danej pozycji pozostałe zmniejszyć ale nie działało dobrze (może coś źle robiłem, ale kodu już niestety nie mam :/)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Lee
post
Post #2





Grupa: Zarejestrowani
Postów: 319
Pomógł: 0
Dołączył: 11.04.2006
Skąd: Chojnów

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


ok działa, nie zauważyłem, że rodzaj kolumny order to varchar (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg) btw. poprawny kod wygląda tak
  1. <?php
  2. $this -> query = mysql_query("SELECT * FROM $tbl_menu WHERE id='$id' LIMIT 1");
  3. while ($this -> result = mysql_fetch_assoc($this -> query)) {
  4. $up = $this -> result['order'];
  5. $position = $this -> result['position'];
  6. }
  7. $this -> query = mysql_query("SELECT * FROM $tbl_menu WHERE `order`<$up AND `position`='$position' ORDER BY `order` DESC LIMIT 1");
  8. while ($this -> result = mysql_fetch_assoc($this -> query)) {
  9. $down = $this -> result['order'];
  10. $id_down = $this -> result['id'];
  11. }
  12. $this -> query = mysql_query("UPDATE $tbl_menu SET `order`='$down' WHERE id='$id' LIMIT 1");
  13. $this -> query = mysql_query("UPDATE $tbl_menu SET `order`='$up' WHERE id='$id_down' LIMIT 1");
  14. header ('Location: admin.php?mod=menu');
  15. ?>
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: 3.10.2025 - 09:10