Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Zapis bazy do tablicy, Niby proste, ale nie do TAKIEJ tablicy, z TAKIEJ bazy
infoo1
post
Post #1





Grupa: Zarejestrowani
Postów: 117
Pomógł: 0
Dołączył: 12.11.2008

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


jak z bazy wygenerować taką tablicę:
  1. <?php
  2. $arr = array(
  3.        'Nagłówek' => array(
  4.          'Anchor1' => 'Href1',
  5.          'Anchor2' => 'Href2',
  6.          'Anchor3' => 'Href3'
  7.        ),
  8.  
  9.        'Nagłówek2' => array(
  10.          'Anchor1' => 'Href1',
  11.          'Anchor2' => 'Href2',
  12.          'Anchor3' => 'Href3'
  13.        )
  14. itd.
  15.      );
  16. ?>

Struktura mojej tabeli:
Kod
+-----+------+---------+------------+------------+
   | id  | type | extends | href       | name       |
   +-----+------+---------+------------+------------+

Id- id menu
Type: są różne typy. Oto one (cyfry to to, co jest wpisane w type):
Kod
1 - menu górne //To nie jest teraz ważne
   2 - nagłówek menu lewego
   3 - menu lewe

Extends - nagłówek tego menu (0 oznacza brak, czyli nagłówek)
Href - adres
Name - nazwa

Czyli np. z tego:
Kod
+-----+------+---------+------------+------------+
   | id  | type | extends | href       | name       |
   +-----+------+---------+------------+------------+
   | 524 | 2    | 0       | 0          | Nagłówek 1 |
   +-----+------+---------+------------+------------+
   | 525 | 3    | 524     | index.php  | Menu 1     |
   +-----+------+---------+------------+------------+
   | 526 | 3    | 524     | index2.php | Menu 2     |
   +-----+------+---------+------------+------------+
   | 527 | 3    | 524     | index3.php | Menu 3     |
   +-----+------+---------+------------+------------+
   | 528 | 3    | 524     | index4.php | Menu 4     |
   +-----+------+---------+------------+------------+
   +-----+------+---------+------------+------------+
   +-----+------+---------+------------+------------+
   | 529 | 2    | 0       | 0          | Nagłówek 2 |
   +-----+------+---------+------------+------------+
   | 530 | 3    | 529     | index.php  | Menu 1     |
   +-----+------+---------+------------+------------+
   | 531 | 3    | 529     | index2.php | Menu 2     |
   +-----+------+---------+------------+------------+
   | 532 | 3    | 529     | index3.php | Menu 3     |
   +-----+------+---------+------------+------------+
   | 533 | 3    | 529     | index4.php | Menu 4     |
   +-----+------+---------+------------+------------+
Powstanie takie menu:
Kod
+------------+
   | Nagłówek 1 |
   +------------+
   --| Menu 1 |--
   --| Menu 2 |--
   --| Menu 3 |--
   --| Menu 4 |--
   +------------+
  
   +------------+
   | Nagłówek 2 |
   +------------+
   --| Menu 1 |--
   --| Menu 2 |--
   --| Menu 3 |--
   --| Menu 4 |--
   +------------+
więc taka tablica:
  1. <?php
  2. $arr = array(
  3.      'Nagłówek 1' => array(
  4.        'Menu 1' => 'index.php',
  5.        'Menu 2' => 'index2.php',
  6.        'Menu 3' => 'index3.php',
  7.        'Menu 4' => 'index4.php'
  8.      ),
  9.  
  10.      'Nagłówek 2' => array(
  11.        'Menu 1' => 'index.php',
  12.        'Menu 2' => 'index2.php',
  13.        'Menu 3' => 'index3.php',
  14.        'Menu 4' => 'index4.php'
  15.      )
  16.    );
  17. ?>
Jak zapisać bazę do takiej tabeli?
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: 22.08.2025 - 00:32