Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Menu sortowanie
sebian
post
Post #1





Grupa: Zarejestrowani
Postów: 38
Pomógł: 0
Dołączył: 2.08.2009

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


Witam.

Problem polega na tym iz nie wiem jak zrobić Menu drzewko. Nie mam problemu z wyświetleniem wynikow z bazy tylko z sortowaniem tak aby wygladało to tak:

Grupa 1
- Produkt 1
- Produkt 2
- Produkt 3
Grupa 2
- Produkt 1
- Produkt 2
- Produkt 3
itd...

Ilość pozycji i grup zależna jest od tego ile sie tego wprowadzi przez panel admina.
Także chodzi mi głownie jak to wyświetlić w takiej strukturze jak wyżej podałem.
Oto co posiadam:

Index.php
  1. <?php
  2.  
  3. include('baza.php');
  4.  
  5. echo '<h2>Kategorie artykułów</h2>';
  6.  
  7.  
  8. $result = mysql_query("SELECT * FROM articles_categories ORDER BY id ASC");
  9. while($row = mysql_fetch_array($result))
  10. {
  11. echo '<a href="cat.php?id='.$row['id'].'"><b>'.stripslashes($row['tytul']).'</b></a><br />';
  12. echo stripslashes($row['opis']).'<br /><br />';
  13. }
  14.  
  15.  
  16.  
  17. ?>


cat.php
  1. <?php
  2.  
  3.  
  4. include('baza.php');
  5.  
  6. $id = (int)$_GET['id'];
  7.  
  8. $result = mysql_query("SELECT * FROM articles_categories WHERE id='$id'");
  9. $row = mysql_fetch_array($result);
  10.  
  11. echo '<h2>'.stripslashes($row['tytul']).'</h2>';
  12.  
  13. $result = mysql_query("SELECT * FROM articles WHERE id_cat='$id' ORDER BY tytul ASC");
  14. while($row = mysql_fetch_array($result))
  15. {
  16. echo '<a href="art.php?id='.$row['id'].'"><b>'.stripslashes($row['tytul']).'</b></a> <!--('.date("d.m.Y, H:i", $row['data']).') --> <br />';
  17. echo stripslashes($row['opis']).'<br /><br />';
  18. }
  19.  
  20.  
  21.  
  22. ?>


art.php
  1. <?php
  2.  
  3.  
  4. include('baza.php');
  5.  
  6. $id = (int)$_GET['id'];
  7.  
  8. if(isset($_POST['ok']))
  9. {
  10. $data = time();
  11.  
  12. if(empty($nick) || empty($tresc)) $komunikat = 'Wpisz wszystkie pola!';
  13. else
  14. {
  15. $query = "INSERT INTO `articles_comments` (`id_art`, `nick`, `tresc`, `data`) VALUES ('$id', '$nick', '$tresc', '$data')";
  16.  
  17. if(mysql_query($query)) $komunikat = 'Pomyslnie dodano komentarz!';
  18. }
  19. }
  20.  
  21. $result = mysql_query("SELECT * FROM articles WHERE id='$id'");
  22. $row = mysql_fetch_array($result);
  23.  
  24. echo '<h2>'.stripslashes($row['tytul']).'</h2>';
  25. echo '<p>'.stripslashes($row['tresc']).'</p>';
  26.  
  27. echo $komunikat;
  28.  
  29.  
  30.  
  31. ?>


I struktura bazy:
  1. CREATE TABLE `articles` (
  2. `id` int(11) NOT NULL AUTO_INCREMENT,
  3. `id_cat` int(11) NOT NULL,
  4. `tytul` text NOT NULL,
  5. `tresc` text NOT NULL,
  6. `opis` text NOT NULL,
  7. `data` int(11) NOT NULL,
  8. `suma` int(11) NOT NULL,
  9. `ocen` int(11) NOT NULL,
  10. PRIMARY KEY (`id`)
  11. ) ENGINE=MyISAM ;
  12.  
  13.  
  14. CREATE TABLE `articles_categories` (
  15. `id` int(11) NOT NULL AUTO_INCREMENT,
  16. `tytul` text NOT NULL,
  17. `opis` text NOT NULL,
  18. PRIMARY KEY (`id`)
  19. ) ENGINE=MyISAM ;
  20.  
  21.  
  22. CREATE TABLE `articles_comments` (
  23. `id` int(11) NOT NULL AUTO_INCREMENT,
  24. `id_art` int(11) NOT NULL,
  25. `nick` text NOT NULL,
  26. `tresc` text NOT NULL,
  27. `data` int(11) NOT NULL,
  28. PRIMARY KEY (`id`)
  29. ) ENGINE=MyISAM ;


Ten post edytował sebian 11.03.2010, 16:14:24
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 21.08.2025 - 01:02